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:
Sébastien Lorber 2021-04-07 18:28:48 +02:00 committed by GitHub
parent 3bcd0a6ab1
commit b743edf5fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 170 additions and 121 deletions

View file

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