feat: load translations from cdn

This commit is contained in:
Stavros
2025-03-30 16:10:42 +03:00
parent 6dc461c11e
commit e43bd651b6
3 changed files with 29 additions and 9 deletions

Binary file not shown.

View File

@@ -18,6 +18,8 @@
"axios": "^1.7.9", "axios": "^1.7.9",
"i18next": "^24.2.3", "i18next": "^24.2.3",
"i18next-browser-languagedetector": "^8.0.4", "i18next-browser-languagedetector": "^8.0.4",
"i18next-chained-backend": "^4.6.2",
"i18next-http-backend": "^3.0.2",
"i18next-resources-to-backend": "^1.2.1", "i18next-resources-to-backend": "^1.2.1",
"react": "^18.3.1", "react": "^18.3.1",
"react-dom": "^18.3.1", "react-dom": "^18.3.1",

View File

@@ -1,19 +1,37 @@
import i18n from 'i18next'; import i18n from "i18next";
import { initReactI18next } from 'react-i18next'; import { initReactI18next } from "react-i18next";
import LanguageDetector from 'i18next-browser-languagedetector'; import LanguageDetector from "i18next-browser-languagedetector";
import resourcesToBackend from 'i18next-resources-to-backend'; import ChainedBackend from "i18next-chained-backend";
import resourcesToBackend from "i18next-resources-to-backend";
import HttpBackend from "i18next-http-backend";
i18n i18n
.use(ChainedBackend)
.use(LanguageDetector) .use(LanguageDetector)
.use(initReactI18next) .use(initReactI18next)
.use(resourcesToBackend((language: string) => import(`./locales/${language}.json`)))
.init({ .init({
fallbackLng: 'en', fallbackLng: "en",
debug: import.meta.env.MODE === 'development', debug: import.meta.env.MODE === "development",
interpolation: { interpolation: {
escapeValue: false, escapeValue: false,
} },
load: "currentOnly",
backend: {
backends: [
HttpBackend,
resourcesToBackend(
(language: string) => import(`./locales/${language}.json`),
),
],
backendOptions: [
{
loadPath: "https://cdn.tinyauth.app/i18n/{{lng}}.json",
},
],
},
}); });
export default i18n; export default i18n;