mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-16 18:46:57 +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
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
import {
|
||||
fileToPath,
|
||||
simpleHash,
|
||||
|
@ -33,6 +34,7 @@ import {
|
|||
findFolderContainingFile,
|
||||
getFolderContainingFile,
|
||||
updateTranslationFileMessages,
|
||||
readDefaultCodeTranslationMessages,
|
||||
} from '../index';
|
||||
import {sum} from 'lodash';
|
||||
|
||||
|
@ -718,3 +720,89 @@ 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'));
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue