-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e0dd132
Showing
26 changed files
with
799 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"presets": [ | ||
["@babel/preset-env", { | ||
"targets": { | ||
"browsers":[ | ||
"defaults" | ||
] | ||
} | ||
}, "@babel/react"] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# EditorConfig is awesome: http://EditorConfig.org | ||
root = true | ||
|
||
[*.{js,jsx,json,ts}] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 | ||
trim_trailing_whitespace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/dist | ||
# /types | ||
/examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"extends": [ | ||
"standard", | ||
"plugin:require-path-exists/recommended" | ||
], | ||
"plugins": [ | ||
"require-path-exists" | ||
], | ||
"globals": { | ||
"describe": false, | ||
"it": false, | ||
"before": false, | ||
"after": false, | ||
"beforeEach": false, | ||
"afterEach": false | ||
}, | ||
"rules": { | ||
"array-bracket-spacing": 0, | ||
"standard/no-callback-literal": 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Number of days of inactivity before an issue becomes stale | ||
daysUntilStale: 7 | ||
# Number of days of inactivity before a stale issue is closed | ||
daysUntilClose: 7 | ||
# Issues with these labels will never be considered stale | ||
exemptLabels: | ||
- "discussion" | ||
- "feature request" | ||
- "bug" | ||
- "breaking change" | ||
- "doc" | ||
- "issue" | ||
- "help wanted" | ||
- "good first issue" | ||
# Label to use when marking an issue as stale | ||
staleLabel: stale | ||
# Comment to post when marking an issue as stale. Set to `false` to disable | ||
markComment: > | ||
This issue has been automatically marked as stale because it has not had | ||
recent activity. It will be closed if no further activity occurs. Thank you | ||
for your contributions. | ||
# Comment to post when closing a stale issue. Set to `false` to disable | ||
closeComment: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: node | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
name: Test on node ${{ matrix.node }} and ${{ matrix.os }} | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
node: [ '20.x', '18.x', '16.x' ] | ||
# os: [ubuntu-latest, windows-latest, macOS-latest] | ||
os: [ubuntu-latest] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node }} | ||
- run: npm install | ||
- run: npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
node_modules | ||
.DS_Store | ||
npm-debug.log | ||
package-lock.json | ||
dist | ||
# types | ||
# !dist/ | ||
# dist/* | ||
# !dist/deno/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.DS_Store | ||
.eslintrc | ||
.gitignore | ||
.npmignore | ||
.editorconfig | ||
.vscode | ||
README.md | ||
.eslintignore | ||
test | ||
scripts | ||
examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"extends": [ | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended" | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": ["@typescript-eslint"], | ||
"env": { "node": true }, | ||
"parserOptions": { | ||
"ecmaVersion": 6, | ||
"sourceType": "module", | ||
"project": "./tsconfig.json", | ||
"createDefaultProgram": true | ||
}, | ||
"rules": { | ||
"semi": ["error", "never"], | ||
"import/export": "off", // this errors on multiple exports (overload interfaces) | ||
"require-path-exists/exists": "off" | ||
}, | ||
"overrides": [ | ||
{ | ||
"files": ["*.d.ts","*.test-d.ts"], | ||
"rules": { | ||
"@typescript-eslint/no-explicit-any": "off" | ||
} | ||
}, | ||
{ | ||
"files": ["*.test-d.ts"], | ||
"rules": { | ||
"@typescript-eslint/no-empty-function": "off", | ||
"@typescript-eslint/explicit-function-return-type": "off", | ||
"@typescript-eslint/no-unused-vars": "off", | ||
"@typescript-eslint/no-non-null-assertion": "off" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
# Introduction | ||
|
||
[](https://github.com/i18next/i18next-resources-for-ts/actions?query=workflow%3Anode) | ||
[](https://www.npmjs.com/package/i18next-resources-for-ts) | ||
|
||
This package helps to transform resources to be used in a typesafe i18next project. | ||
|
||
# Getting started | ||
|
||
Source can be loaded via [npm](https://www.npmjs.com/package/i18next-resources-for-ts). | ||
|
||
```bash | ||
# npm package | ||
$ npm install i18next-resources-for-ts | ||
``` | ||
|
||
## Usage via code (toc): | ||
|
||
```js | ||
import { tocForResources } from 'i18next-resources-for-ts' | ||
|
||
const nsA = { | ||
name: 'nsA', | ||
path: '/some/path/locales/en/nsA.json' | ||
} | ||
const nsB = { | ||
name: 'nsB', | ||
path: '/some/path/locales/en/nsB.json' | ||
} | ||
|
||
const toc = tocForResources([nsA, nsB], '/some/path') | ||
// import nsA from './locales/en/nsA.json'; | ||
// import nsB from './locales/en/nsB.json'; | ||
|
||
// export default { | ||
// nsA, | ||
// nsB | ||
// } | ||
``` | ||
|
||
## Usage via code (merge): | ||
|
||
```js | ||
import { mergeResources } from 'i18next-resources-for-ts' | ||
|
||
const nsA = { | ||
name: 'nsA', | ||
path: '/some/path/locales/en/nsA.json', | ||
resources: { | ||
k1: 'v1', | ||
k2: 'v2', | ||
k3: { | ||
d3: 'v3' | ||
} | ||
} | ||
} | ||
const nsB = { | ||
name: 'nsB', | ||
path: '/some/path/locales/en/nsB.json', | ||
resources: { | ||
k21: 'v21', | ||
k22: 'v22', | ||
k23: { | ||
d23: 'v23' | ||
} | ||
} | ||
} | ||
|
||
const merged = mergeResources([nsA, nsB]) | ||
// { | ||
// nsA: { | ||
// k1: 'v1', | ||
// k2: 'v2', | ||
// k3: { | ||
// d3: 'v3' | ||
// } | ||
// }, | ||
// nsB: { | ||
// k21: 'v21', | ||
// k22: 'v22', | ||
// k23: { | ||
// d23: 'v23' | ||
// } | ||
// } | ||
// } | ||
``` | ||
|
||
Usage via CLI: | ||
|
||
```sh | ||
# use it with npx | ||
npx i18next-resources-for-ts subcommand -i /Users/user/my/input -o /Users/user/my/output | ||
|
||
# or install it globally | ||
npm install i18next-resources-for-ts -g | ||
|
||
# subcommand is either toc or merge | ||
# -i is the input path | ||
# -o is the output path | ||
# if the output path is not provided, it will use the input path as base path for the result file | ||
|
||
i18next-resources-for-ts toc -i /Users/user/my/input -o /Users/user/my/output.ts | ||
i18next-resources-for-ts merge -i /Users/user/my/input -o /Users/user/my/output.json | ||
# i18next-resources-for-ts toc /Users/user/my/input -o /Users/user/my/output | ||
# i18next-resources-for-ts toc -o /Users/user/my/output | ||
# i18next-resources-for-ts toc -i /Users/user/my/input | ||
# i18next-resources-for-ts toc | ||
``` | ||
|
||
*Make sure your folder structure contains all relevant namespaces (in your source/reference language):* | ||
|
||
```sh | ||
└── namespace.json | ||
``` | ||
|
||
i.e. | ||
```sh | ||
├── translation.json | ||
└── common.json | ||
``` | ||
|
||
--- | ||
|
||
<h3 align="center">Gold Sponsors</h3> | ||
|
||
<p align="center"> | ||
<a href="https://locize.com/" target="_blank"> | ||
<img src="https://raw.githubusercontent.com/i18next/i18next/master/assets/locize_sponsor_240.gif" width="240px"> | ||
</a> | ||
</p> | ||
|
||
--- | ||
|
||
**From the creators of i18next: localization as a service - locize.com** | ||
|
||
A translation management system built around the i18next ecosystem - [locize.com](https://locize.com). | ||
|
||
 | ||
|
||
With using [locize](http://locize.com/?utm_source=react_i18next_readme&utm_medium=github) you directly support the future of i18next. | ||
|
||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
const getFiles = (srcpath) => { | ||
return fs.readdirSync(srcpath).filter((file) => { | ||
return !fs.statSync(path.join(srcpath, file)).isDirectory() | ||
}).filter((file) => path.extname(file) === '.json').map((file) => path.join(srcpath, file)) | ||
} | ||
|
||
const getDirectories = (srcpath) => { | ||
return fs.readdirSync(srcpath).filter((file) => { | ||
return fs.statSync(path.join(srcpath, file)).isDirectory() | ||
}).map((dir) => path.join(srcpath, dir)) | ||
} | ||
|
||
function getAllFiles (srcpath) { | ||
let files = getFiles(srcpath) | ||
const dirs = getDirectories(srcpath) | ||
dirs.forEach((dir) => { | ||
files = files.concat(getAllFiles(dir)) | ||
}) | ||
return files | ||
} | ||
|
||
module.exports = (p) => { | ||
const allFiles = getAllFiles(p) | ||
|
||
return allFiles.map((file) => { | ||
const namespace = JSON.parse(fs.readFileSync(file, 'utf-8')) | ||
const sepFile = file.split(path.sep) | ||
const fileName = sepFile[sepFile.length - 1] | ||
const name = path.parse(fileName).name | ||
|
||
return { | ||
name, | ||
path: file, | ||
resources: namespace | ||
} | ||
}) | ||
} |
Oops, something went wrong.