diff --git a/package-lock.json b/package-lock.json index 0b4f296..0eb4935 100644 --- a/package-lock.json +++ b/package-lock.json @@ -62,6 +62,7 @@ "ai": "^2.2.25", "handlebars": "^4.7.8", "i18next": "^23.7.6", + "i18next-browser-languagedetector": "^7.2.0", "markdown-it": "^13.0.2", "next": "latest", "openai": "^4.20.0", @@ -4386,6 +4387,14 @@ "@babel/runtime": "^7.23.2" } }, + "node_modules/i18next-browser-languagedetector": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/i18next-browser-languagedetector/-/i18next-browser-languagedetector-7.2.0.tgz", + "integrity": "sha512-U00DbDtFIYD3wkWsr2aVGfXGAj2TgnELzOX9qv8bT0aJtvPV9CRO77h+vgmHFBMe7LAxdwvT/7VkCWGya6L3tA==", + "dependencies": { + "@babel/runtime": "^7.23.2" + } + }, "node_modules/ignore": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.0.tgz", diff --git a/package.json b/package.json index 1515de8..f50a45e 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "ai": "^2.2.25", "handlebars": "^4.7.8", "i18next": "^23.7.6", + "i18next-browser-languagedetector": "^7.2.0", "markdown-it": "^13.0.2", "next": "latest", "openai": "^4.20.0", diff --git a/src/i18n/i18n.js b/src/i18n/i18n.js index 907bd72..5121821 100644 --- a/src/i18n/i18n.js +++ b/src/i18n/i18n.js @@ -1,5 +1,6 @@ import i18n from 'i18next' import { initReactI18next } from 'react-i18next' +import LanguageDetector from 'i18next-browser-languagedetector'; // the translations // (tip move them in a JSON file and import them, @@ -29,8 +30,11 @@ const resources = { i18n .use(initReactI18next) // passes i18n down to react-i18next + .use(LanguageDetector) .init({ resources, + fallbackLng: 'en', + debug: true, // lng: 'zh', // language to use, more information here: https://www.i18next.com/overview/configuration-options#languages-namespaces-resources // you can use the i18n.changeLanguage function to change the language manually: https://www.i18next.com/overview/api#changelanguage // if you're using a language detector, do not define the lng option @@ -38,6 +42,9 @@ i18n interpolation: { escapeValue: false // react already safes from xss } + }, (err, t) => { + if (err) return console.log('something went wrong loading', err) + console.log('i18n loaded successfully') }) export default i18n \ No newline at end of file