Prioritize Intl's locale instead of navigator.languages

pull/1247/head
Lim Chee Aun 2025-08-23 08:45:33 +08:00
rodzic 55745f5b51
commit 75b8f0cf02
2 zmienionych plików z 5 dodań i 4 usunięć

Wyświetl plik

@ -6,7 +6,7 @@ function initLocales() {
try {
const dtfLocale = new Intl.DateTimeFormat().resolvedOptions().locale;
if (!newLocales.includes(dtfLocale)) {
newLocales.push(dtfLocale);
newLocales.unshift(dtfLocale);
}
} catch {}
return newLocales;

Wyświetl plik

@ -95,10 +95,11 @@ test.describe('DateTimeFormat locale combination behavior', () => {
expect(navigator.language).toBe('en-GB');
expect(formatted).toBeTruthy();
// Verify that the DateTimeFormat uses en-GB (British formatting)
// Verify the negotiation:
// Environment default may be prioritized by implementation, otherwise user region should be respected.
const resolvedLocale = dtf.resolvedOptions().locale;
// Should resolve to en-GB since the locale combination logic works
expect(resolvedLocale).toBe('en-GB');
const envDefault = new Intl.DateTimeFormat().resolvedOptions().locale;
expect([envDefault, 'en-GB', 'en']).toContain(resolvedLocale);
});
test('should handle different formatting options', () => {