test(i18n): normalize underscore locale tags in shared frontend loader (#257)
All checks were successful
CI / test-and-quality (push) Successful in 3m13s
CI / test-and-quality (pull_request) Successful in 2m55s

This commit is contained in:
2026-03-02 03:02:04 +00:00
parent 9219648231
commit f87e0b60cf
2 changed files with 3 additions and 1 deletions

View File

@@ -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;
} }

View File

@@ -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');
}); });