Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(web): prevent auth client timeout by optimizing i18n loading

(justin)randoneering4522365e6e9b
diff --git a/apps/web/package.json b/apps/web/package.json
index 33b397000..cf4c07d9d 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -78,6 +78,7 @@
"highlight.js": "^11.11.1",
"hono": "^4.13.0",
"i18next": "^26.3.6",
+ "i18next-resources-to-backend": "^1.2.1",
"immer": "^11.1.16",
"input-otp": "^1.4.2",
"lowlight": "^3.3.0",
diff --git a/apps/web/src/lib/i18n/index.ts b/apps/web/src/lib/i18n/index.ts
index 93a3333de..71e25c79d 100644
--- a/apps/web/src/lib/i18n/index.ts
+++ b/apps/web/src/lib/i18n/index.ts
@@ -1,10 +1,12 @@
import {
type AppLocale,
defaultLocale,
- resources,
+ isSupportedLocale,
+ loadLocale,
supportedLocales,
} from "@i18n/resources";
import i18n from "i18next";
+import resourcesToBackend from "i18next-resources-to-backend";
import { initReactI18next } from "react-i18next";
function getLanguageCode(locale: string) {
@@ -40,15 +42,23 @@ export function getBrowserLocale(): string | null {
return navigator.language || navigator.languages?.[0] || null;
}
-void i18n.use(initReactI18next).init({
- resources,
- lng: resolveLocale(null, getBrowserLocale()),
- fallbackLng: defaultLocale,
- ns: Object.keys(resources[defaultLocale]),
- defaultNS: "common",
- interpolation: {
- escapeValue: false,
- },
-});
+void i18n
+ .use(
+ resourcesToBackend((language: string, namespace: string) => {
+ const locale = isSupportedLocale(language) ? language : defaultLocale;
+ return loadLocale(locale).then(
+ (resources) => (resources as Record<string, unknown>)[namespace],
+ );
+ }),
+ )
+ .use(initReactI18next)
+ .init({
+ lng: resolveLocale(null, getBrowserLocale()),
+ fallbackLng: defaultLocale,
+ defaultNS: "common",
+ interpolation: {
+ escapeValue: false,
+ },
+ });
export { i18n };
diff --git a/apps/web/vite.config.ts b/apps/web/vite.config.ts
index d19de9443..47952ac1b 100644
--- a/apps/web/vite.config.ts
+++ b/apps/web/vite.config.ts
@@ -60,11 +60,7 @@ export default defineConfig({
// to end users; the Sentry plugin still attaches them to uploaded
// releases.
sourcemap: "hidden",
- rollupOptions: {
- output: {
- manualChunks: undefined,
- },
- },
+ rollupOptions: {},
commonjsOptions: {
include: [/better-auth/, /node_modules/],
transformMixedEsModules: true,
diff --git a/i18n/resources.ts b/i18n/resources.ts
index 2454cbddf..23633b94f 100644
--- a/i18n/resources.ts
+++ b/i18n/resources.ts
@@ -1,21 +1,3 @@
-import deDE from "./de-DE.json";
-import elGR from "./el-GR.json";
-import enUS from "./en-US.json";
-import esES from "./es-ES.json";
-import frFR from "./fr-FR.json";
-import hiIN from "./hi-IN.json";
-import idID from "./id-ID.json";
-import itIT from "./it-IT.json";
-import koKR from "./ko-KR.json";
-import mkMK from "./mk-MK.json";
-import nlNL from "./nl-NL.json";
-import ptBR from "./pt-BR.json";
-import ruRU from "./ru-RU.json";
-import trTR from "./tr-TR.json";
-import ukUA from "./uk-UA.json";
-import viVN from "./vi-VN.json";
-import zhCN from "./zh-CN.json";
-
export const supportedLocales = [
"mk-MK",
"nl-NL",
@@ -40,22 +22,45 @@ export type AppLocale = (typeof supportedLocales)[number];
export const defaultLocale: AppLocale = "en-US";
-export const resources = {
- "mk-MK": mkMK,
- "nl-NL": nlNL,
- "en-US": enUS,
- "de-DE": deDE,
- "el-GR": elGR,
- "fr-FR": frFR,
- "hi-IN": hiIN,
- "id-ID": idID,
- "it-IT": itIT,
- "es-ES": esES,
- "ko-KR": koKR,
- "pt-BR": ptBR,
- "ru-RU": ruRU,
- "tr-TR": trTR,
- "uk-UA": ukUA,
- "vi-VN": viVN,
- "zh-CN": zhCN,
-} as const;
+export function isSupportedLocale(locale: string): locale is AppLocale {
+ return (supportedLocales as readonly string[]).includes(locale);
+}
+
+export async function loadLocale(locale: AppLocale): Promise<object> {
+ switch (locale) {
+ case "de-DE":
+ return (await import("./de-DE.json")).default;
+ case "el-GR":
+ return (await import("./el-GR.json")).default;
+ case "en-US":
+ return (await import("./en-US.json")).default;
+ case "es-ES":
+ return (await import("./es-ES.json")).default;
+ case "fr-FR":
+ return (await import("./fr-FR.json")).default;
+ case "hi-IN":
+ return (await import("./hi-IN.json")).default;
+ case "id-ID":
+ return (await import("./id-ID.json")).default;
+ case "it-IT":
+ return (await import("./it-IT.json")).default;
+ case "ko-KR":
+ return (await import("./ko-KR.json")).default;
+ case "mk-MK":
+ return (await import("./mk-MK.json")).default;
+ case "nl-NL":
+ return (await import("./nl-NL.json")).default;
+ case "pt-BR":
+ return (await import("./pt-BR.json")).default;
+ case "ru-RU":
+ return (await import("./ru-RU.json")).default;
+ case "tr-TR":
+ return (await import("./tr-TR.json")).default;
+ case "uk-UA":
+ return (await import("./uk-UA.json")).default;
+ case "vi-VN":
+ return (await import("./vi-VN.json")).default;
+ case "zh-CN":
+ return (await import("./zh-CN.json")).default;
+ }
+}