locales/<lang>? only containes translation.json (#2633)

This commit is contained in:
Jaco Greeff 2020-04-26 12:51:59 +02:00 committed by GitHub
parent 6818cab3a5
commit 3b6891878c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 21 additions and 38 deletions

View File

@ -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/<id>` 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.

View File

@ -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"
}

View File

@ -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",

View File

@ -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": "",

View File

@ -1 +0,0 @@
[]

View File

@ -1 +0,0 @@
[]

View File

@ -29,14 +29,14 @@ type StringsMod = Record<string, Strings>;
type Languages = Record<string, Strings>;
async function retrieveJson (url: string): Promise<any> {
const response = await fetch(url);
const response = await fetch(`locales/${url}`);
return response.json();
}
async function retrieveEnglish (): Promise<StringsMod> {
const paths: Array<string> = await retrieveJson('locales/en/index.json');
const strings: Strings[] = await Promise.all(paths.map((path) => retrieveJson(`locales/en/${path}`)));
const paths: Array<string> = 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<StringsMod> {
}, {});
}
async function retrieveLanguage (lng: string): Promise<Strings> {
const paths: Array<string> = 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<Defaults> {
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) {

View File

@ -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();
}

View File

@ -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 () {