Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[web] Bundle translations but load them lazily

Manav Rathia98a29800bbe
diff --git a/web/packages/next/i18n.ts b/web/packages/next/i18n.ts
index 3f51d5c101..31ca08ada9 100644
--- a/web/packages/next/i18n.ts
+++ b/web/packages/next/i18n.ts
@@ -3,7 +3,7 @@ import { logError } from "@/utils/logging";
import { includes } from "@/utils/type-guards";
import { getUserLocales } from "get-user-locale";
import i18n from "i18next";
-import Backend from "i18next-http-backend";
+import resourcesToBackend from "i18next-resources-to-backend";
import { initReactI18next } from "react-i18next";
import { object, string } from "yup";
@@ -55,7 +55,15 @@ export const setupI18n = async () => {
await i18n
// i18next-http-backend: Asynchronously loads translations over HTTP
// https://github.com/i18next/i18next-http-backend
- .use(Backend)
+ // .use(Backend)
+ .use(
+ resourcesToBackend(
+ (language: string, namespace: string) =>
+ import(
+ `../../apps/photos/public/locales/${language}/${namespace}.json`
+ ),
+ ),
+ )
// react-i18next: React support
// Pass the i18n instance to react-i18next.
.use(initReactI18next)
diff --git a/web/packages/next/package.json b/web/packages/next/package.json
index d21ee5c53d..6b300b4942 100644
--- a/web/packages/next/package.json
+++ b/web/packages/next/package.json
@@ -10,6 +10,7 @@
"get-user-locale": "^2.3",
"i18next": "^23.10",
"i18next-http-backend": "^2.5",
+ "i18next-resources-to-backend": "^1.2.0",
"next": "^14.1",
"react": "^18",
"react-dom": "^18",
diff --git a/web/yarn.lock b/web/yarn.lock
index 6e7f48715c..cc54f1ce48 100644
--- a/web/yarn.lock
+++ b/web/yarn.lock
@@ -3002,6 +3002,13 @@ i18next-http-backend@^2.5:
dependencies:
cross-fetch "4.0.0"
+i18next-resources-to-backend@^1.2.0:
+ version "1.2.0"
+ resolved "https://registry.yarnpkg.com/i18next-resources-to-backend/-/i18next-resources-to-backend-1.2.0.tgz#4e0ea0c093bf1acb3eb47972a3002b84a1fec3b2"
+ integrity sha512-8f1l03s+QxDmCfpSXCh9V+AFcxAwIp0UaroWuyOx+hmmv8484GcELHs+lnu54FrNij8cDBEXvEwhzZoXsKcVpg==
+ dependencies:
+ "@babel/runtime" "^7.23.2"
+
i18next@^23.10:
version "23.10.0"
resolved "https://registry.yarnpkg.com/i18next/-/i18next-23.10.0.tgz#fb328794ae692e6fdde0564259e421f4203c4a2c"
@@ -3454,7 +3461,7 @@ [email protected]:
dependencies:
libsodium "^0.7.0"
[email protected], libsodium@^0.7.0:
+libsodium@^0.7.0:
version "0.7.9"
resolved "https://registry.yarnpkg.com/libsodium/-/libsodium-0.7.9.tgz#4bb7bcbf662ddd920d8795c227ae25bbbfa3821b"
integrity sha512-gfeADtR4D/CM0oRUviKBViMGXZDgnFdMKMzHsvBdqLBHd9ySi6EtYnmuhHVDDYgYpAO8eU8hEY+F8vIUAPh08A==