test(i18n): normalize underscore locale tags in shared frontend loader (#257)
This commit is contained in:
@@ -8,7 +8,7 @@ export const DEFAULT_LOCALE = lobbyCatalog.locales.default as SupportedLocale;
|
|||||||
export const SUPPORTED_LOCALES = lobbyCatalog.locales.supported as readonly SupportedLocale[];
|
export const SUPPORTED_LOCALES = lobbyCatalog.locales.supported as readonly SupportedLocale[];
|
||||||
|
|
||||||
export function normalizeLocale(rawLocale?: string | null): SupportedLocale {
|
export function normalizeLocale(rawLocale?: string | null): SupportedLocale {
|
||||||
const locale = (rawLocale ?? '').trim().toLowerCase();
|
const locale = (rawLocale ?? '').trim().toLowerCase().replace(/_/g, '-');
|
||||||
if ((SUPPORTED_LOCALES as readonly string[]).includes(locale)) {
|
if ((SUPPORTED_LOCALES as readonly string[]).includes(locale)) {
|
||||||
return locale as SupportedLocale;
|
return locale as SupportedLocale;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,9 @@ describe('shared lobby i18n loader parity', () => {
|
|||||||
|
|
||||||
it('normalizes browser-style locale tags to supported keyspace locales', () => {
|
it('normalizes browser-style locale tags to supported keyspace locales', () => {
|
||||||
expect(normalizeLocale('da-DK')).toBe('da');
|
expect(normalizeLocale('da-DK')).toBe('da');
|
||||||
|
expect(normalizeLocale('da_DK')).toBe('da');
|
||||||
expect(normalizeLocale('en-US')).toBe('en');
|
expect(normalizeLocale('en-US')).toBe('en');
|
||||||
|
expect(normalizeLocale('en_US')).toBe('en');
|
||||||
expect(normalizeLocale('fr-FR')).toBe('en');
|
expect(normalizeLocale('fr-FR')).toBe('en');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user