mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-02 19:03:38 +02:00
feat(v2): Add i18n default code translation bundles (#4215)
* Add default code translation bundles * fix tests
This commit is contained in:
parent
1b3c9be530
commit
6a94ad989c
12 changed files with 430 additions and 5 deletions
|
@ -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 {};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue