feat(i18n): complete Simplified Chinese translations (#14474)
* feat(i18n): complete Simplified Chinese translation * chore: check for missing translation items * fix: put the prevent merge conflict line at the end * feat: put new translations at the beginning * Rename translate-locales.ts to check-missing-translations.ts * Update package.json to use check-missing-translations --------- Co-authored-by: Keith Williams <keithwillcode@gmail.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: Omar López <zomars@me.com>
This commit is contained in:
co-authored by
Keith Williams
Peer Richelsen
Omar López
parent
e58ce4af71
commit
4cf89d273e
@@ -0,0 +1,51 @@
|
||||
import { readFileSync, readdirSync, writeFileSync } from "fs";
|
||||
import { join } from "path";
|
||||
|
||||
const TEMPLATE_LANGUAGE = "en";
|
||||
const SPECIFIC_LOCALES = process.argv.slice(2) || [];
|
||||
const LOCALES_PATH = join(__dirname, "../public/static/locales");
|
||||
|
||||
const ALL_LOCALES = readdirSync(LOCALES_PATH);
|
||||
|
||||
const templateJsonPath = join(LOCALES_PATH, `${TEMPLATE_LANGUAGE}/common.json`);
|
||||
const templateJson: { [key: string]: string } = JSON.parse(readFileSync(templateJsonPath, "utf-8"));
|
||||
|
||||
const missingTranslationLocales: string[] = [];
|
||||
// If locales are not specified, then check all folders under `public/static/locales`
|
||||
(SPECIFIC_LOCALES.length ? SPECIFIC_LOCALES : ALL_LOCALES).forEach((locale: string) => {
|
||||
if (locale === TEMPLATE_LANGUAGE) return;
|
||||
if (!ALL_LOCALES.includes(locale)) {
|
||||
missingTranslationLocales.push(locale);
|
||||
console.log(`
|
||||
❌ ${locale} is not found in ${LOCALES_PATH}!
|
||||
If you want to create a new locale, Please create common.json under ${join(LOCALES_PATH, locale)}.
|
||||
`);
|
||||
return;
|
||||
}
|
||||
|
||||
const localeJsonPath = join(LOCALES_PATH, `${locale}/common.json`);
|
||||
const localeJson: { [key: string]: string } = JSON.parse(readFileSync(localeJsonPath, "utf8"));
|
||||
|
||||
if (Object.keys(templateJson).length === Object.keys(localeJson).length) return;
|
||||
|
||||
const missingTranslations: { [key: string]: string } = {};
|
||||
missingTranslationLocales.push(locale);
|
||||
Object.entries(templateJson).forEach(([key, value]: [string, string]) => {
|
||||
if (key in localeJson) return;
|
||||
|
||||
missingTranslations[key] = value;
|
||||
});
|
||||
|
||||
const newLocaleJson = {
|
||||
...missingTranslations,
|
||||
...localeJson,
|
||||
};
|
||||
writeFileSync(localeJsonPath, JSON.stringify(newLocaleJson, null, 2));
|
||||
});
|
||||
|
||||
if (missingTranslationLocales.length) {
|
||||
console.log("🌍 The following locales need to be translated: ");
|
||||
console.log(` ${missingTranslationLocales.join(", ")}`);
|
||||
} else {
|
||||
console.log("💯 All the locales are completely translated!");
|
||||
}
|
||||
Reference in New Issue
Block a user