Skip to content

Commit 8713203

Browse files
committed
fix(locale): Small fix for language selector
1 parent 7985e42 commit 8713203

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

packages/fxa-settings/src/models/hooks.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,12 @@ describe('useCmsInfoState', () => {
410410
});
411411

412412
it('should fetch when l10nEnabled is false but browser language is English', async () => {
413-
// Mock English browser language but non-English selected locale
413+
// Mock English browser language and English selected locale
414414
Object.defineProperty(navigator, 'language', {
415415
writable: true,
416416
value: 'en-GB',
417417
});
418-
require('../contexts/DynamicLocalizationContext').useDynamicLocalization.mockReturnValue({ currentLocale: 'fr-FR' });
418+
require('../contexts/DynamicLocalizationContext').useDynamicLocalization.mockReturnValue({ currentLocale: 'en-US' });
419419

420420
mockUrlQueryData.get.mockImplementation((key: string) => {
421421
if (key === 'client_id') return '1234567890abcdef';

packages/fxa-settings/src/models/hooks.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,14 @@ export function useCmsInfoState() {
244244

245245
// If l10nEnabled is false, only fetch for English locales
246246
// Check both browser language and user's selected locale
247-
const isEnglishBrowser = navigator.language.startsWith('en');
248-
const isEnglishSelected = currentLocale.startsWith('en');
247+
let isEnglish = false;
248+
if (currentLocale) {
249+
isEnglish = currentLocale.startsWith('en');
250+
} else if (navigator.language) {
251+
isEnglish = navigator.language.startsWith('en');
252+
}
249253

250-
return isEnglishBrowser || isEnglishSelected;
254+
return isEnglish;
251255
}
252256

253257
if (

0 commit comments

Comments
 (0)