feat(v2): Add i18n default code translation bundles (#4215)

* Add default code translation bundles

* fix tests
This commit is contained in:
Sébastien Lorber 2021-02-12 11:35:09 +01:00 committed by GitHub
parent 1b3c9be530
commit 6a94ad989c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 430 additions and 5 deletions

View file

@ -602,3 +602,35 @@ export function updateTranslationFileMessages(
})),
};
}
export async function readDefaultCodeTranslationMessages({
dirPath,
locale,
}: {
dirPath: string;
locale: string;
}): Promise<Record<string, string>> {
const fileNamesToTry = [locale];
if (locale.includes('_')) {
const language = locale.split('_')[0];
if (language) {
fileNamesToTry.push(language);
}
}
// Return the content of the first file that match
// fr_FR.json => fr.json => nothing
for (const fileName of fileNamesToTry) {
const filePath = path.resolve(dirPath, `${fileName}.json`);
// eslint-disable-next-line no-await-in-loop
if (await fs.pathExists(filePath)) {
// eslint-disable-next-line no-await-in-loop
const fileContent = await fs.readFile(filePath, 'utf8');
return JSON.parse(fileContent);
}
}
return {};
}