-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(project): implement i18next-parser
- Loading branch information
1 parent
6fb4692
commit 22c7abd
Showing
12 changed files
with
700 additions
and
25 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 |
---|---|---|
|
@@ -4,3 +4,4 @@ node_modules | |
.idea | ||
.DS_Store | ||
/coverage | ||
src/i18n/locales/**/*_old.json |
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 @@ | ||
// i18next-parser.config.js | ||
|
||
module.exports = { | ||
contextSeparator: '_', | ||
createOldCatalogs: true, | ||
defaultNamespace: 'common', | ||
defaultValue: '', | ||
indentation: 2, | ||
keepRemoved: false, | ||
keySeparator: '.', | ||
lexers: { | ||
mjs: ['JavascriptLexer'], | ||
js: ['JavascriptLexer'], | ||
ts: ['JavascriptLexer'], | ||
jsx: ['JsxLexer'], | ||
tsx: ['JsxLexer'], | ||
default: ['JavascriptLexer'] | ||
}, | ||
lineEnding: 'auto', | ||
locales: ['en_US', 'nl_NL'], | ||
namespaceSeparator: ':', | ||
output: 'src/i18n/locales/$LOCALE/$NAMESPACE.json', | ||
sort: 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
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,36 @@ | ||
/** | ||
* This script generates all i18next resource entries. | ||
*/ | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const localesPath = './src/i18n/locales'; | ||
const defaultLocale = 'en_US'; | ||
|
||
const fileHeader = `// This file is generated, do not modify manually. | ||
// Run \`$ yarn i18next:scan\` to update this file | ||
`; | ||
|
||
const files = fs.readdirSync(localesPath); | ||
const locales = files.filter(file => !/\.ts/.test(file)); | ||
|
||
if (!locales.includes(defaultLocale)) { | ||
throw new Error('The default locale is missing from locales folder.'); | ||
} | ||
|
||
const namespaces = fs.readdirSync(path.join(localesPath, defaultLocale)) | ||
.filter(namespace => !/_old\.json/.test(namespace)); // filter *_old namespaces generated by i18next-parser | ||
|
||
locales.forEach((locale) => { | ||
const content = namespaces.reduce((contents, namespace) => { | ||
return contents + `export { default as ${namespace.replace('.json', '')} } from \'./${locale}/${namespace}\';\n`; | ||
}, fileHeader); | ||
|
||
fs.writeFileSync(path.join(localesPath, `${locale}.ts`), content, { encoding: 'utf-8' }); | ||
}); | ||
|
||
console.log(''); | ||
console.log(`Generated entries for the following locales: ${locales.join(', ')}`); | ||
console.log(''); |
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
// This file is generated, do not modify manually. | ||
// Run `$ yarn i18next:scan` to update this file | ||
|
||
export { default as common } from './en_US/common.json'; | ||
export { default as video } from './en_US/video.json'; | ||
export { default as menu } from './en_US/menu.json'; | ||
export { default as video } from './en_US/video.json'; |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"open_menu": "Open menu", | ||
"close_menu": "Close menu", | ||
"menu": "Menu", | ||
"home": "Home", | ||
"menu": "Menu", | ||
"open_menu": "Open menu", | ||
"settings": "Settings" | ||
} |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"start_watching": "Start watching", | ||
"trailer": "Trailer", | ||
"favorite": "Favorite", | ||
"share": "Share" | ||
"share": "Share", | ||
"start_watching": "Start watching", | ||
"trailer": "Trailer" | ||
} |
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,6 @@ | ||
// This file is generated, do not modify manually. | ||
// Run `$ yarn i18next:scan` to update this file | ||
|
||
export { default as common } from './nl_NL/common.json'; | ||
export { default as menu } from './nl_NL/menu.json'; | ||
export { default as video } from './nl_NL/video.json'; |
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,7 @@ | ||
{ | ||
"back": "", | ||
"close": "", | ||
"play_item": "", | ||
"slide_left": "", | ||
"slide_right": "" | ||
} |
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,7 @@ | ||
{ | ||
"close_menu": "", | ||
"home": "", | ||
"menu": "", | ||
"open_menu": "", | ||
"settings": "" | ||
} |
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,6 @@ | ||
{ | ||
"favorite": "", | ||
"share": "", | ||
"start_watching": "", | ||
"trailer": "" | ||
} |
Oops, something went wrong.