mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-16 10:37:20 +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
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
import {
|
||||
fileToPath,
|
||||
simpleHash,
|
||||
|
@ -34,7 +33,6 @@ import {
|
|||
findFolderContainingFile,
|
||||
getFolderContainingFile,
|
||||
updateTranslationFileMessages,
|
||||
readDefaultCodeTranslationMessages,
|
||||
parseMarkdownHeadingId,
|
||||
} from '../index';
|
||||
import {sum} from 'lodash';
|
||||
|
@ -722,92 +720,6 @@ describe('updateTranslationFileMessages', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('readDefaultCodeTranslationMessages', () => {
|
||||
const dirPath = path.resolve(
|
||||
__dirname,
|
||||
'__fixtures__',
|
||||
'defaultCodeTranslations',
|
||||
);
|
||||
|
||||
async function readAsJSON(filename: string) {
|
||||
return JSON.parse(
|
||||
await fs.readFile(path.resolve(dirPath, filename), 'utf8'),
|
||||
);
|
||||
}
|
||||
|
||||
test('for empty locale', async () => {
|
||||
await expect(
|
||||
readDefaultCodeTranslationMessages({
|
||||
locale: '',
|
||||
dirPath,
|
||||
}),
|
||||
).resolves.toEqual({});
|
||||
});
|
||||
|
||||
test('for unexisting locale', async () => {
|
||||
await expect(
|
||||
readDefaultCodeTranslationMessages({
|
||||
locale: 'es',
|
||||
dirPath,
|
||||
}),
|
||||
).resolves.toEqual({});
|
||||
});
|
||||
|
||||
test('for fr but bad folder', async () => {
|
||||
await expect(
|
||||
readDefaultCodeTranslationMessages({
|
||||
locale: '',
|
||||
dirPath: __dirname,
|
||||
}),
|
||||
).resolves.toEqual({});
|
||||
});
|
||||
|
||||
test('for fr', async () => {
|
||||
await expect(
|
||||
readDefaultCodeTranslationMessages({
|
||||
locale: 'fr',
|
||||
dirPath,
|
||||
}),
|
||||
).resolves.toEqual(await readAsJSON('fr.json'));
|
||||
});
|
||||
|
||||
test('for fr_FR', async () => {
|
||||
await expect(
|
||||
readDefaultCodeTranslationMessages({
|
||||
locale: 'fr_FR',
|
||||
dirPath,
|
||||
}),
|
||||
).resolves.toEqual(await readAsJSON('fr_FR.json'));
|
||||
});
|
||||
|
||||
test('for en', async () => {
|
||||
await expect(
|
||||
readDefaultCodeTranslationMessages({
|
||||
locale: 'en',
|
||||
dirPath,
|
||||
}),
|
||||
).resolves.toEqual(await readAsJSON('en.json'));
|
||||
});
|
||||
|
||||
test('for en_US', async () => {
|
||||
await expect(
|
||||
readDefaultCodeTranslationMessages({
|
||||
locale: 'en_US',
|
||||
dirPath,
|
||||
}),
|
||||
).resolves.toEqual(await readAsJSON('en.json'));
|
||||
});
|
||||
|
||||
test('for en_WHATEVER', async () => {
|
||||
await expect(
|
||||
readDefaultCodeTranslationMessages({
|
||||
locale: 'en_WHATEVER',
|
||||
dirPath,
|
||||
}),
|
||||
).resolves.toEqual(await readAsJSON('en.json'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseMarkdownHeadingId', () => {
|
||||
test('can parse simple heading without id', () => {
|
||||
expect(parseMarkdownHeadingId('## Some heading')).toEqual({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue