Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

load translations on demand

Blue Mouseba31a8f871bf
diff --git a/package.json b/package.json
index a0eeb4887..11af09cbb 100644
--- a/package.json
+++ b/package.json
@@ -19,6 +19,7 @@
"i18n-iso-countries": "^7.2.0",
"i18next": "^21.6.6",
"i18next-browser-languagedetector": "^6.1.2",
+ "i18next-http-backend": "^1.3.1",
"lodash": "^4.17.21",
"nanoid": "^3.2.0",
"prismjs": "^1.26.0",
@@ -64,13 +65,13 @@
]
},
"devDependencies": {
+ "@testing-library/jest-dom": "^5.16.1",
+ "@testing-library/react": "^12.1.2",
+ "@testing-library/user-event": "^13.5.0",
"autoprefixer": "^10.4.2",
"cross-env": "^7.0.3",
"postcss": "^8.4.5",
"source-map-explorer": "^2.5.2",
- "@testing-library/jest-dom": "^5.16.1",
- "@testing-library/react": "^12.1.2",
- "@testing-library/user-event": "^13.5.0",
"tailwindcss": "^3.0.15"
}
}
diff --git a/src/i18n/de.json b/public/locales/de.json
similarity index 100%
rename from src/i18n/de.json
rename to public/locales/de.json
diff --git a/src/i18n/en.json b/public/locales/en.json
similarity index 100%
rename from src/i18n/en.json
rename to public/locales/en.json
diff --git a/src/i18n/hi.json b/public/locales/hi.json
similarity index 100%
rename from src/i18n/hi.json
rename to public/locales/hi.json
diff --git a/src/i18n/ru.json b/public/locales/ru.json
similarity index 100%
rename from src/i18n/ru.json
rename to public/locales/ru.json
diff --git a/src/i18n/uk.json b/public/locales/uk.json
similarity index 100%
rename from src/i18n/uk.json
rename to public/locales/uk.json
diff --git a/src/i18n/zh.json b/public/locales/zh.json
similarity index 100%
rename from src/i18n/zh.json
rename to public/locales/zh.json
diff --git a/src/i18next.js b/src/i18next.js
index f8cb935a7..2fa9ffadc 100644
--- a/src/i18next.js
+++ b/src/i18next.js
@@ -1,14 +1,9 @@
import i18next from 'i18next'
import LanguageDetector from 'i18next-browser-languagedetector'
+import backend from 'i18next-http-backend'
import _isString from 'lodash/isString'
import { whitelist, defaultLanguage } from 'redux/constants'
import { setItem } from 'utils/localstorage'
-import en from './i18n/en.json'
-import ru from './i18n/ru.json'
-import uk from './i18n/uk.json'
-import de from './i18n/de.json'
-import hi from './i18n/hi.json'
-import zh from './i18n/zh.json'
const lngDetector = new LanguageDetector()
lngDetector.addDetector({
@@ -28,8 +23,12 @@ lngDetector.addDetector({
})
i18next
+ .use(backend)
.use(lngDetector)
.init({
+ backend: {
+ loadPath: '/locales/{{lng}}.json',
+ },
detection: {
order: ['localStorage', 'customDetector'],
lookupLocalStorage: 'language',
@@ -45,14 +44,8 @@ i18next
return key
},
whitelist,
- resources: {
- en: { common: en },
- ru: { common: ru },
- uk: { common: uk },
- de: { common: de },
- hi: { common: hi },
- zh: { common: zh },
- },
+ ns: ['common'],
+ defaultNS: 'common',
})
export default i18next