🐛(frontend) fix browser language detection

The `Default language` E2E test detected the browser language was not
automatically detected when user does not have any cookie, it was always
falling back on the defaut language (en).
This commit is contained in:
Quentin BEY
2025-05-06 15:32:23 +02:00
parent 4a08a9ec92
commit aa3d90b686
3 changed files with 19 additions and 1 deletions

View File

@@ -21,6 +21,7 @@
"@openfun/cunningham-react": "3.0.0",
"@tanstack/react-query": "5.72.1",
"i18next": "24.2.3",
"i18next-browser-languagedetector": "8.1.0",
"lodash": "4.17.21",
"luxon": "3.6.1",
"next": "15.2.5",

View File

@@ -1,4 +1,5 @@
import i18n from 'i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
import { initReactI18next } from 'react-i18next';
import {
@@ -8,7 +9,11 @@ import {
} from './conf';
import resources from './translations.json';
export const availableFrontendLanguages: readonly string[] =
Object.keys(resources);
i18n
.use(LanguageDetector)
.use(initReactI18next)
.init({
resources,
@@ -23,7 +28,7 @@ i18n
interpolation: {
escapeValue: false,
},
preload: Object.keys(LANGUAGES_ALLOWED),
preload: availableFrontendLanguages,
nsSeparator: false,
keySeparator: false,
})

View File

@@ -944,6 +944,11 @@
dependencies:
regenerator-runtime "^0.14.0"
"@babel/runtime@^7.23.2":
version "7.27.1"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.27.1.tgz#9fce313d12c9a77507f264de74626e87fd0dc541"
integrity sha512-1x3D2xEk2fRo3PAhwQwu5UubzgiVWSXTBfWpVd2Mx2AzRqJuDJCsgaDVZ7HB5iGzDW1Hl1sWN2mFyKjmR9uAog==
"@babel/template@^7.25.9", "@babel/template@^7.26.9", "@babel/template@^7.27.0", "@babel/template@^7.3.3":
version "7.27.0"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.27.0.tgz#b253e5406cc1df1c57dcd18f11760c2dbf40c0b4"
@@ -6627,6 +6632,13 @@ human-signals@^2.1.0:
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0"
integrity sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==
i18next-browser-languagedetector@8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/i18next-browser-languagedetector/-/i18next-browser-languagedetector-8.1.0.tgz#e7fcc1084e9ca8fece329c8c05b000a6e25bd82e"
integrity sha512-mHZxNx1Lq09xt5kCauZ/4bsXOEA2pfpwSoU11/QTJB+pD94iONFwp+ohqi///PwiFvjFOxe1akYCdHyFo1ng5Q==
dependencies:
"@babel/runtime" "^7.23.2"
i18next-parser@9.3.0:
version "9.3.0"
resolved "https://registry.yarnpkg.com/i18next-parser/-/i18next-parser-9.3.0.tgz#65c226cac54cd2783b59715a366be1e3515dd8e6"