aboutsummaryrefslogtreecommitdiffstats
path: root/apps/web/lib/i18n/client.ts
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2024-11-17 00:33:28 +0000
committerGitHub <noreply@github.com>2024-11-17 00:33:28 +0000
commit4354ee7ba1c6ac9a9567944ae6169b1664e0ea8a (patch)
treee27c9070930514d77582bae00b3350274116179c /apps/web/lib/i18n/client.ts
parent9f2c7be23769bb0f4102736a683710b1a1939661 (diff)
downloadkarakeep-4354ee7ba1c6ac9a9567944ae6169b1664e0ea8a.tar.zst
feature: Add i18n support. Fixes #57 (#635)
* feature(web): Add basic scaffolding for i18n * refactor: Switch most of the app's strings to use i18n strings * fix: Remove unused i18next-resources-for-ts command * Add user setting * More translations * Drop the german translation for now
Diffstat (limited to 'apps/web/lib/i18n/client.ts')
-rw-r--r--apps/web/lib/i18n/client.ts33
1 files changed, 33 insertions, 0 deletions
diff --git a/apps/web/lib/i18n/client.ts b/apps/web/lib/i18n/client.ts
new file mode 100644
index 00000000..1c56a88a
--- /dev/null
+++ b/apps/web/lib/i18n/client.ts
@@ -0,0 +1,33 @@
+"use client";
+
+import i18next from "i18next";
+import resourcesToBackend from "i18next-resources-to-backend";
+import {
+ initReactI18next,
+ useTranslation as useTranslationOrg,
+} from "react-i18next";
+
+import { getOptions, languages } from "./settings";
+
+const runsOnServerSide = typeof window === "undefined";
+
+i18next
+ .use(initReactI18next)
+ .use(
+ resourcesToBackend(
+ (language: string, namespace: string) =>
+ import(`./locales/${language}/${namespace}.json`),
+ ),
+ )
+ .init({
+ ...getOptions(),
+ lng: undefined, // let detect the language on client side
+ debug: false,
+ interpolation: {
+ escapeValue: false, // not needed for react as it escapes by default
+ },
+ preload: runsOnServerSide ? languages : [],
+ });
+
+export const useTranslation = useTranslationOrg;
+export const i18n = i18next;