fix(i18n): return the correct locale from filenames (#5922)
This commit is contained in:
parent
bf8b94f011
commit
6a42f98b51
@ -207,6 +207,36 @@ describe('i18n', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getLocaleFromPath', () => {
|
||||||
|
it('should return the locale from folder name in the path when structure is I18N_STRUCTURE.MULTIPLE_FOLDERS', () => {
|
||||||
|
expect(
|
||||||
|
i18n.getLocaleFromPath(
|
||||||
|
i18n.I18N_STRUCTURE.MULTIPLE_FOLDERS,
|
||||||
|
'md',
|
||||||
|
'src/content/en/index.md',
|
||||||
|
),
|
||||||
|
).toEqual('en');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the locale extension from the file name when structure is I18N_STRUCTURE.MULTIPLE_FILES', () => {
|
||||||
|
expect(
|
||||||
|
i18n.getLocaleFromPath(i18n.I18N_STRUCTURE.MULTIPLE_FILES, 'md', 'src/content/index.en.md'),
|
||||||
|
).toEqual('en');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('issue #5909: return the correct locale extension for language gd', () => {
|
||||||
|
expect(
|
||||||
|
i18n.getLocaleFromPath(i18n.I18N_STRUCTURE.MULTIPLE_FILES, 'md', 'src/content/index.gd.md'),
|
||||||
|
).toEqual('gd');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return an empty string when structure is I18N_STRUCTURE.SINGLE_FILE', () => {
|
||||||
|
expect(
|
||||||
|
i18n.getLocaleFromPath(i18n.I18N_STRUCTURE.SINGLE_FILE, 'md', 'src/content/index.md'),
|
||||||
|
).toEqual('');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('getI18nFiles', () => {
|
describe('getI18nFiles', () => {
|
||||||
const locales = ['en', 'de', 'fr'];
|
const locales = ['en', 'de', 'fr'];
|
||||||
const default_locale = 'en';
|
const default_locale = 'en';
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Map, List } from 'immutable';
|
import { Map, List } from 'immutable';
|
||||||
import { set, trimEnd, groupBy, escapeRegExp } from 'lodash';
|
import { set, groupBy, escapeRegExp } from 'lodash';
|
||||||
|
|
||||||
import { selectEntrySlug } from '../reducers/collections';
|
import { selectEntrySlug } from '../reducers/collections';
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ export function getLocaleFromPath(structure: I18N_STRUCTURE, extension: string,
|
|||||||
return parts.pop();
|
return parts.pop();
|
||||||
}
|
}
|
||||||
case I18N_STRUCTURE.MULTIPLE_FILES: {
|
case I18N_STRUCTURE.MULTIPLE_FILES: {
|
||||||
const parts = trimEnd(path, `.${extension}`);
|
const parts = path.slice(0, -`.${extension}`.length);
|
||||||
return parts.split('.').pop();
|
return parts.split('.').pop();
|
||||||
}
|
}
|
||||||
case I18N_STRUCTURE.SINGLE_FILE:
|
case I18N_STRUCTURE.SINGLE_FILE:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user