diff --git a/I18N.md b/I18N.md index b7d5f1106f..6cf284ab3b 100644 --- a/I18N.md +++ b/I18N.md @@ -17,4 +17,4 @@ Here you will find a dropdown of all the available languages and all the modules ## Adding a new language -The process is similar for the above, but does require a new folder with the language identifier to be added, with an empty `translation.json` (containing only `{}`) & `index.json` file (containing only `[]`) +The process is similar for the above, but does require a new folder with the language identifier to be added. Create `packages/apps/public/locales/` folder with an empty `translation.json` (containing only `{}`). After addition of the folder, run `yarn build:i18n` and then the new language will be available for update as per the process in the previous section. diff --git a/packages/apps/public/locales/en/app-i18n.json b/packages/apps/public/locales/en/app-i18n.json index 690bda1022..a90fde9fe6 100644 --- a/packages/apps/public/locales/en/app-i18n.json +++ b/packages/apps/public/locales/en/app-i18n.json @@ -1,8 +1,6 @@ { + "Generate {{lng}}/translation.json": "Generate {{lng}}/translation.json", "the language to display translations for": "the language to display translations for", - "{{p}}% done": "{{p}}% done", "the module to display strings for": "the module to display strings for", - "Generate {{lng}}/translate.json": "Generate {{lng}}/translate.json", - "{{done}}/{{total}}, {{progress}}% done": "{{done}}/{{total}}, {{progress}}% done", - "Generate {{lng}}/translation.json": "Generate {{lng}}/translation.json" -} + "{{done}}/{{total}}, {{progress}}% done": "{{done}}/{{total}}, {{progress}}% done" +} \ No newline at end of file diff --git a/packages/apps/public/locales/en/index.json b/packages/apps/public/locales/en/index.json index c15e8a22bd..af75d8726b 100644 --- a/packages/apps/public/locales/en/index.json +++ b/packages/apps/public/locales/en/index.json @@ -9,6 +9,7 @@ "app-explorer.json", "app-extrinsics.json", "app-generic-asset.json", + "app-i18n.json", "app-js.json", "app-parachains.json", "app-settings.json", diff --git a/packages/apps/public/locales/en/translation.json b/packages/apps/public/locales/en/translation.json index 890ba18ee9..1455169210 100644 --- a/packages/apps/public/locales/en/translation.json +++ b/packages/apps/public/locales/en/translation.json @@ -145,7 +145,6 @@ "Forget this contract": "", "Forks": "", "General": "", - "Generate {{lng}}/translate.json": "", "Generate {{lng}}/translation.json": "", "Genesis Hash": "", "Genesis Hash refers to initial state of the chain, it cannot be changed once the chain is launched": "", @@ -893,7 +892,6 @@ "{{h}} hrs": "", "{{m}} mins": "", "{{name}} ({{size}} bytes)": "", - "{{p}}% done": "", "{{relayDispatchQueueSize}} dispatch messages pending": "", "{{s}} s": "", "{{threshold}}, not passing": "", diff --git a/packages/apps/public/locales/ja/index.json b/packages/apps/public/locales/ja/index.json deleted file mode 100644 index 0637a088a0..0000000000 --- a/packages/apps/public/locales/ja/index.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/packages/apps/public/locales/zh/index.json b/packages/apps/public/locales/zh/index.json deleted file mode 100644 index 0637a088a0..0000000000 --- a/packages/apps/public/locales/zh/index.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/packages/page-i18n/src/index.tsx b/packages/page-i18n/src/index.tsx index f9bc75d9f5..a6f4ae0f9d 100644 --- a/packages/page-i18n/src/index.tsx +++ b/packages/page-i18n/src/index.tsx @@ -29,14 +29,14 @@ type StringsMod = Record; type Languages = Record; async function retrieveJson (url: string): Promise { - const response = await fetch(url); + const response = await fetch(`locales/${url}`); return response.json(); } async function retrieveEnglish (): Promise { - const paths: Array = await retrieveJson('locales/en/index.json'); - const strings: Strings[] = await Promise.all(paths.map((path) => retrieveJson(`locales/en/${path}`))); + const paths: Array = await retrieveJson('en/index.json'); + const strings: Strings[] = await Promise.all(paths.map((path) => retrieveJson(`en/${path}`))); return strings.reduce((language: StringsMod, strings, index): StringsMod => { language[paths[index]] = strings; @@ -45,27 +45,13 @@ async function retrieveEnglish (): Promise { }, {}); } -async function retrieveLanguage (lng: string): Promise { - const paths: Array = await retrieveJson(`locales/${lng}/index.json`); - const translation: Strings = await retrieveJson(`locales/${lng}/translation.json`).catch(() => ({})); - const modules: Strings[] = await Promise.all(paths.map((path) => retrieveJson(`locales/${lng}/${path}`))); - - modules.forEach((strings): void => { - Object.keys(strings).forEach((key): void => { - if (strings[key]) { - translation[key] = strings[key]; - } - }); - }); - - return translation; -} - async function retrieveAll (): Promise { - const _keys: string[] = await retrieveJson('locales/index.json'); + const _keys: string[] = await retrieveJson('index.json'); const keys = _keys.filter((key) => key !== 'en'); const english = await retrieveEnglish(); - const languages = await Promise.all(keys.map(retrieveLanguage)); + const languages = await Promise.all( + keys.map((lng) => retrieveJson(`${lng}/translation.json`)) + ); return { english, @@ -108,7 +94,7 @@ function calcProgress (english: StringsMod, language: Strings): Progress { } function doDownload (strings: Strings): void { - const sanitized = Object.keys(strings).reduce((result: Strings, key): Strings => { + const sanitized = Object.keys(strings).sort().reduce((result: Strings, key): Strings => { const sanitized = strings[key].trim(); if (sanitized) { diff --git a/scripts/i18nLint.js b/scripts/i18nLint.js index b46008a784..99e3664513 100644 --- a/scripts/i18nLint.js +++ b/scripts/i18nLint.js @@ -15,7 +15,7 @@ function getEntries (langRoot) { !['.', '..'].includes(entry) && fs.lstatSync(path.join(langRoot, entry)).isFile() && entry.endsWith('.json') && - !['app-i18n.json', 'index.json', 'translation.json'].includes(entry) + !['index.json', 'translation.json'].includes(entry) ) .sort(); } diff --git a/scripts/i18nSort.js b/scripts/i18nSort.js index 0d82c8ce4b..0b18fdb052 100644 --- a/scripts/i18nSort.js +++ b/scripts/i18nSort.js @@ -14,7 +14,7 @@ function getEntries (langRoot) { !['.', '..'].includes(entry) && fs.lstatSync(path.join(langRoot, entry)).isFile() && entry.endsWith('.json') && - !['app-i18n.json', 'index.json'].includes(entry) + !['index.json'].includes(entry) ) .sort(); } @@ -35,10 +35,12 @@ function sortLanguage (lang) { fs.writeFileSync(filename, JSON.stringify(sorted, null, 2)); }); - fs.writeFileSync( - path.join(langRoot, 'index.json'), - JSON.stringify(entries.filter((entry) => !['translation.json'].includes(entry)), null, 2) - ); + if (lang === 'en') { + fs.writeFileSync( + path.join(langRoot, 'index.json'), + JSON.stringify(entries.filter((entry) => !['translation.json'].includes(entry)), null, 2) + ); + } } function checkLanguages () {