Skip to content

Commit

Permalink
chore: move sync script to root
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristiaanScheermeijer committed Apr 12, 2024
1 parent 4247b96 commit 95c5b37
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
1 change: 0 additions & 1 deletion knip.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const config: KnipConfig = {
'global',
'start:test',
'codecept:*',
'i18next',
],
},
'packages/common': {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"format:prettier": "prettier --write \"{**/*,*}.{js,ts,jsx,tsx}\"",
"format:stylelint": "stylelint --fix '**/*.{css,scss}'",
"i18next-diff": "npx ts-node ./scripts/i18next/diff-translations",
"i18next-update": "npx ts-node ./scripts/i18next/update-translations.ts && yarn i18next",
"i18next-update": "npx ts-node ./scripts/i18next/update-translations.ts && yarn web i18next",
"i18next:sync": "npx ts-node ./scripts/i18next/sync-translations.ts",
"lint": "run-p -c lint:*",
"lint:eslint": "eslint \"{**/*,*}.{js,ts,jsx,tsx}\"",
"lint:prettier": "prettier --check \"{**/*,*}.{js,ts,jsx,tsx}\"",
Expand Down
1 change: 0 additions & 1 deletion platforms/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"codecept:mobile": "cd test-e2e && rm -rf \"./output/mobile\" && codeceptjs run-workers --suites ${WORKER_COUNT:=8} --config ./codecept.mobile.cjs",
"generate-pwa-assets": "pwa-assets-generator",
"i18next": "npx ts-node ./scripts/i18next/parse-translations.ts",
"i18next:sync": "npx ts-node ./scripts/i18next/sync-translations.ts",
"lint:ts": "tsc --pretty --noEmit -p ./ && tsc --pretty --noEmit -p ./test-e2e",
"serve-report:desktop": "cd test-e2e && allure serve \"./output/desktop\"",
"serve-report:mobile": "cd test-e2e && allure serve \"./output/mobile\"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function flattenObject(obj: Trans, parentKey: string = ''): Record<string, strin
// Recursively flatten nested objects
const nestedFlattened = flattenObject(value, newKey);
result = { ...result, ...nestedFlattened };
} else {
} else if (typeof value === 'string') {
// Assign the value to the flattened key
result[newKey] = value;
}
Expand Down Expand Up @@ -65,23 +65,31 @@ function applyMissingTranslations(translations: Trans, sourceTranslations: Recor
}

async function getPlatformLocalesPath(platformPath: string) {
const extensions = ['js', 'cjs', 'mjs', 'ts'];

try {
const parserConfig = (await import(join(platformPath, 'i18next-parser.config.js')))?.default;
for (const index in extensions) {
const configPath = join(platformPath, `i18next-parser.config.${extensions[index]}`);

if (!existsSync(configPath)) continue;

if (typeof parserConfig.output === 'string') {
return parserConfig.output.replace('/$LOCALE', '').replace('/$NAMESPACE.json', '');
const parserConfig = (await import(configPath))?.default;

if (typeof parserConfig.output === 'string') {
return parserConfig.output.replace('/$LOCALE', '').replace('/$NAMESPACE.json', '');
}
}
} catch {
console.error('Failed to load i18next-parser.config.js');
} catch (error: unknown) {
console.error('Failed to load i18next-parser.config.js', error);
}

return join(platformPath, 'public/locales');
}

async function fillMissingTranslations(sourcePlatform: string, targetPlatform: string) {
const translations: Record<string, Record<string, string>> = {};
const sourcePlatformPath = join(process.cwd(), '../', sourcePlatform);
const targetPlatformPath = join(process.cwd(), '../', targetPlatform);
const sourcePlatformPath = join(process.cwd(), 'platforms', sourcePlatform);
const targetPlatformPath = join(process.cwd(), 'platforms', targetPlatform);

if (!existsSync(sourcePlatformPath)) {
console.error(`Source platform doesn't exist ${sourcePlatformPath}`);
Expand Down

0 comments on commit 95c5b37

Please sign in to comment.