mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-06 04:42:40 +02:00
feat(v2): default theme translations: locale "pt" should load "pt-BR" translations (#4581)
* code translation utils => locale "pt" should attempt to load "pt-BR" (not "pt-PT") * useless async test
This commit is contained in:
parent
3bcd0a6ab1
commit
b743edf5fb
5 changed files with 170 additions and 121 deletions
|
@ -22,6 +22,8 @@ import {
|
|||
// @ts-expect-error: no typedefs :s
|
||||
import resolvePathnameUnsafe from 'resolve-pathname';
|
||||
|
||||
export * from './codeTranslationsUtils';
|
||||
|
||||
const fileHash = new Map();
|
||||
export async function generate(
|
||||
generatedFilesDir: string,
|
||||
|
@ -642,39 +644,6 @@ 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
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
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 {};
|
||||
}
|
||||
|
||||
// Input: ## Some heading {#some-heading}
|
||||
// Output: {text: "## Some heading", id: "some-heading"}
|
||||
export function parseMarkdownHeadingId(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue