Skip to content

Commit

Permalink
feat: auto add translation keys to json
Browse files Browse the repository at this point in the history
Uses i18next-parser to automatically extract translation keys
from js and svelte files.
  • Loading branch information
asedmammad committed Mar 7, 2024
1 parent f55525c commit 08aa60b
Show file tree
Hide file tree
Showing 7 changed files with 1,649 additions and 1,621 deletions.
38 changes: 38 additions & 0 deletions i18next-parser.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// i18next-parser.config.ts
import { getLanguages } from './src/lib/i18n/index.ts';

const getLangCodes = async () => {
const languages = await getLanguages();
return languages.map((l) => l.code);
};

export default {
contextSeparator: '_',
createOldCatalogs: false,
defaultNamespace: 'translation',
defaultValue: '',
indentation: 2,
keepRemoved: false,
keySeparator: false,
lexers: {
svelte: ['JavascriptLexer'],
js: ['JavascriptLexer'], // if you're writing jsx inside .js files, change this to JsxLexer
ts: ['JavascriptLexer'],

default: ['JavascriptLexer']
},
lineEnding: 'auto',
locales: await getLangCodes(),
namespaceSeparator: false,
output: 'src/lib/i18n/locales/$LOCALE/$NAMESPACE.json',
pluralSeparator: '_',
input: 'src/**/*.{js,svelte}',
sort: true,
verbose: true,
failOnWarnings: false,
failOnUpdate: false,
customValueTemplate: null,
resetDefaultValueLocale: null,
i18nextOptions: null,
yamlOptions: null
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"eslint": "^8.56.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-svelte": "^2.30.0",
"i18next-parser": "^8.13.0",
"postcss": "^8.4.31",
"prettier": "^2.8.0",
"prettier-plugin-svelte": "^2.10.1",
Expand Down
646 changes: 322 additions & 324 deletions src/lib/i18n/locales/de/translation.json

Large diffs are not rendered by default.

646 changes: 322 additions & 324 deletions src/lib/i18n/locales/en/translation.json

Large diffs are not rendered by default.

647 changes: 322 additions & 325 deletions src/lib/i18n/locales/fa/translation.json

Large diffs are not rendered by default.

646 changes: 322 additions & 324 deletions src/lib/i18n/locales/fr/translation.json

Large diffs are not rendered by default.

646 changes: 322 additions & 324 deletions src/lib/i18n/locales/uk/translation.json

Large diffs are not rendered by default.

0 comments on commit 08aa60b

Please sign in to comment.