diff --git a/package.json b/package.json index 5a7dd65..14ac47e 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "fuse.js": "^7.0.0", "i18next": "^23.6.0", "i18next-browser-languagedetector": "^7.1.0", - "i18next-http-backend": "^2.3.1", + "i18next-resources-to-backend": "^1.2.0", "immer": "^10.0.3", "lodash": "^4.17.21", "meilisearch": "^0.35.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 01e8b9c..2551f0e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -62,9 +62,9 @@ dependencies: i18next-browser-languagedetector: specifier: ^7.1.0 version: 7.1.0 - i18next-http-backend: - specifier: ^2.3.1 - version: 2.3.1 + i18next-resources-to-backend: + specifier: ^1.2.0 + version: 1.2.0 immer: specifier: ^10.0.3 version: 10.0.3 @@ -1584,14 +1584,6 @@ packages: - encoding dev: false - /cross-fetch@4.0.0: - resolution: {integrity: sha512-e4a5N8lVvuLgAWgnCrLr2PP0YyDOTHa9H/Rj54dirp61qXnNq46m82bRhNqIA5VccJtWBvPTFRV3TtvHUKPB1g==} - dependencies: - node-fetch: 2.7.0 - transitivePeerDependencies: - - encoding - dev: false - /cross-spawn@7.0.3: resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==} engines: {node: '>= 8'} @@ -2072,12 +2064,10 @@ packages: '@babel/runtime': 7.22.15 dev: false - /i18next-http-backend@2.3.1: - resolution: {integrity: sha512-jnagFs5cnq4ryb+g92Hex4tB5kj3tWmiRWx8gHMCcE/PEgV1fjH5rC7xyJmPSgyb9r2xgcP8rvZxPKgsmvMqTw==} + /i18next-resources-to-backend@1.2.0: + resolution: {integrity: sha512-8f1l03s+QxDmCfpSXCh9V+AFcxAwIp0UaroWuyOx+hmmv8484GcELHs+lnu54FrNij8cDBEXvEwhzZoXsKcVpg==} dependencies: - cross-fetch: 4.0.0 - transitivePeerDependencies: - - encoding + '@babel/runtime': 7.23.2 dev: false /i18next@23.6.0: diff --git a/public/locales/en/common.json b/src/locales/en/common.json similarity index 100% rename from public/locales/en/common.json rename to src/locales/en/common.json diff --git a/public/locales/en/dashboard.json b/src/locales/en/dashboard.json similarity index 100% rename from public/locales/en/dashboard.json rename to src/locales/en/dashboard.json diff --git a/public/locales/en/document.json b/src/locales/en/document.json similarity index 100% rename from public/locales/en/document.json rename to src/locales/en/document.json diff --git a/public/locales/en/footer.json b/src/locales/en/footer.json similarity index 100% rename from public/locales/en/footer.json rename to src/locales/en/footer.json diff --git a/public/locales/en/header.json b/src/locales/en/header.json similarity index 100% rename from public/locales/en/header.json rename to src/locales/en/header.json diff --git a/public/locales/en/instance.json b/src/locales/en/instance.json similarity index 100% rename from public/locales/en/instance.json rename to src/locales/en/instance.json diff --git a/public/locales/en/key.json b/src/locales/en/key.json similarity index 100% rename from public/locales/en/key.json rename to src/locales/en/key.json diff --git a/public/locales/en/sys.json b/src/locales/en/sys.json similarity index 100% rename from public/locales/en/sys.json rename to src/locales/en/sys.json diff --git a/public/locales/en/task.json b/src/locales/en/task.json similarity index 100% rename from public/locales/en/task.json rename to src/locales/en/task.json diff --git a/public/locales/en/upload.json b/src/locales/en/upload.json similarity index 100% rename from public/locales/en/upload.json rename to src/locales/en/upload.json diff --git a/public/locales/zh/common.json b/src/locales/zh/common.json similarity index 100% rename from public/locales/zh/common.json rename to src/locales/zh/common.json diff --git a/public/locales/zh/dashboard.json b/src/locales/zh/dashboard.json similarity index 100% rename from public/locales/zh/dashboard.json rename to src/locales/zh/dashboard.json diff --git a/public/locales/zh/document.json b/src/locales/zh/document.json similarity index 100% rename from public/locales/zh/document.json rename to src/locales/zh/document.json diff --git a/public/locales/zh/footer.json b/src/locales/zh/footer.json similarity index 100% rename from public/locales/zh/footer.json rename to src/locales/zh/footer.json diff --git a/public/locales/zh/header.json b/src/locales/zh/header.json similarity index 100% rename from public/locales/zh/header.json rename to src/locales/zh/header.json diff --git a/public/locales/zh/instance.json b/src/locales/zh/instance.json similarity index 100% rename from public/locales/zh/instance.json rename to src/locales/zh/instance.json diff --git a/public/locales/zh/key.json b/src/locales/zh/key.json similarity index 100% rename from public/locales/zh/key.json rename to src/locales/zh/key.json diff --git a/public/locales/zh/sys.json b/src/locales/zh/sys.json similarity index 100% rename from public/locales/zh/sys.json rename to src/locales/zh/sys.json diff --git a/public/locales/zh/task.json b/src/locales/zh/task.json similarity index 100% rename from public/locales/zh/task.json rename to src/locales/zh/task.json diff --git a/public/locales/zh/upload.json b/src/locales/zh/upload.json similarity index 100% rename from public/locales/zh/upload.json rename to src/locales/zh/upload.json diff --git a/src/utils/i18n.ts b/src/utils/i18n.ts index 3cc9da0..c56de87 100644 --- a/src/utils/i18n.ts +++ b/src/utils/i18n.ts @@ -1,7 +1,7 @@ import i18n from 'i18next'; import { initReactI18next } from 'react-i18next'; -import Backend from 'i18next-http-backend'; import LanguageDetector from 'i18next-browser-languagedetector'; +import resourcesToBackend from 'i18next-resources-to-backend'; export const SUPPORTED_LANGUAGES = ['en', 'zh'] as const; export type SUPPORTED_LANGUAGE = (typeof SUPPORTED_LANGUAGES)[number]; @@ -22,7 +22,8 @@ export const NAMESPACES = [ ] as const; i18n - .use(Backend) + // .use(Backend) + .use(resourcesToBackend((language: string, namespace: string) => import(`../locales/${language}/${namespace}.json`))) .use(LanguageDetector) .use(initReactI18next) // passes i18n down to react-i18next .init({ @@ -30,10 +31,6 @@ i18n fallbackLng: SUPPORTED_LANGUAGES[0], ns: NAMESPACES, fallbackNS: NAMESPACES[0], - backend: { - // fs backend options - loadPath: '/locales/{{lng}}/{{ns}}.json', - }, interpolation: { escapeValue: false, // react already safes from xss },