test(#257): normalize underscore locale tags in shared frontend loader #265

Merged
integrator-bot merged 1 commits from dev/issue-257-shared-i18n-locale-underscore-guard into main 2026-03-02 04:08:43 +01:00
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 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)) {
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', () => {
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('fr-FR')).toBe('en');
});