refactor(core): reorganize functions (#7037)

This commit is contained in:
Joshua Chen 2022-03-28 17:12:36 +08:00 committed by GitHub
parent c81d21a641
commit 85a79fd9b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
64 changed files with 1207 additions and 1304 deletions

View file

@ -5,10 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/
import path from 'path';
import {
mergeTranslations,
updateTranslationFileMessages,
getPluginI18nPath,
localizePath,
} from '../i18nUtils';
describe('mergeTranslations', () => {
@ -93,3 +95,85 @@ describe('getPluginI18nPath', () => {
).toMatchInlineSnapshot(`"/i18n/zh-Hans/plugin-content-docs"`);
});
});
describe('localizePath', () => {
it('localizes url path with current locale', () => {
expect(
localizePath({
pathType: 'url',
path: '/baseUrl',
i18n: {
defaultLocale: 'en',
locales: ['en', 'fr'],
currentLocale: 'fr',
localeConfigs: {},
},
options: {localizePath: true},
}),
).toBe('/baseUrl/fr/');
});
it('localizes fs path with current locale', () => {
expect(
localizePath({
pathType: 'fs',
path: '/baseFsPath',
i18n: {
defaultLocale: 'en',
locales: ['en', 'fr'],
currentLocale: 'fr',
localeConfigs: {},
},
options: {localizePath: true},
}),
).toBe(`${path.sep}baseFsPath${path.sep}fr`);
});
it('localizes path for default locale, if requested', () => {
expect(
localizePath({
pathType: 'url',
path: '/baseUrl/',
i18n: {
defaultLocale: 'en',
locales: ['en', 'fr'],
currentLocale: 'en',
localeConfigs: {},
},
options: {localizePath: true},
}),
).toBe('/baseUrl/en/');
});
it('does not localize path for default locale by default', () => {
expect(
localizePath({
pathType: 'url',
path: '/baseUrl/',
i18n: {
defaultLocale: 'en',
locales: ['en', 'fr'],
currentLocale: 'en',
localeConfigs: {},
},
// options: {localizePath: true},
}),
).toBe('/baseUrl/');
});
it('localizes path for non-default locale by default', () => {
expect(
localizePath({
pathType: 'url',
path: '/baseUrl/',
i18n: {
defaultLocale: 'en',
locales: ['en', 'fr'],
currentLocale: 'en',
localeConfigs: {},
},
// options: {localizePath: true},
}),
).toBe('/baseUrl/');
});
});