Skip to content

Commit 7ddbfca

Browse files
committed
Fix: prioritize the browser language detection.
1 parent c3e517d commit 7ddbfca

File tree

1 file changed

+10
-3
lines changed
  • netflix-create-react-vite-app

1 file changed

+10
-3
lines changed

netflix-create-react-vite-app/i18n.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,30 @@ i18n
99
.use(HttpApi)
1010
.init({
1111
supportedLngs: ['en', 'nl'],
12-
lng: 'en',
1312
fallbackLng: 'en',
1413
interpolation: {
1514
escapeValue: false, // not needed for react as it escapes by default
1615
},
1716
detection: {
1817
order: [
18+
'navigator',
1919
'querystring',
2020
'cookie',
2121
'localStorage',
2222
'sessionStorage',
23-
'navigator',
2423
'htmlTag',
2524
'path',
2625
'subdomain',
2726
],
28-
caches: ['cookie'],
27+
caches: ['localStorage', 'cookie'],
28+
lookupLocalStorage: 'i18nextLng',
29+
lookupCookie: 'i18nextLng',
30+
convertDetectedLanguage: (lng) => {
31+
// Map language variants to supported languages
32+
if (lng && lng.startsWith('nl')) return 'nl';
33+
if (lng && lng.startsWith('en')) return 'en';
34+
return lng;
35+
},
2936
},
3037
backend: {
3138
loadPath: '/locales/{{lng}}/translation.json',

0 commit comments

Comments
 (0)