From df20f6bc5977cccea37f9297c6011d058bd07d92 Mon Sep 17 00:00:00 2001 From: Codemod Bot Date: Fri, 20 Dec 2024 18:14:24 +0000 Subject: [PATCH] feat: Add setup file --- apps/frontend/app/i18n.ts | 47 ++++++++++++++++++++++++++++ apps/frontend/app/layout.tsx | 6 +++- apps/frontend/package.json | 9 +++++- apps/vsce/webview/package.json | 9 +++++- apps/vsce/webview/src/main/i18n.ts | 47 ++++++++++++++++++++++++++++ apps/vsce/webview/src/main/index.tsx | 2 ++ 6 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 apps/frontend/app/i18n.ts create mode 100644 apps/vsce/webview/src/main/i18n.ts diff --git a/apps/frontend/app/i18n.ts b/apps/frontend/app/i18n.ts new file mode 100644 index 000000000..63873a665 --- /dev/null +++ b/apps/frontend/app/i18n.ts @@ -0,0 +1,47 @@ +import type { Resource } from "i18next"; +import i18n from "i18next"; +import LanguageDetector from "i18next-browser-languagedetector"; +import { initReactI18next } from "react-i18next"; + +void i18n + .use({ + type: "backend", + read( + language: string, + namespace: string, + callback: (errorValue: unknown, translations: null | Resource) => void, + ) { + import(`./${namespace}/locales/${language}.json`) + .then((resources) => { + callback(null, resources as unknown as Resource); + }) + .catch((error) => { + callback(error, null); + }); + }, + }) + .use(LanguageDetector) + .use(initReactI18next) + .init({ + fallbackLng: "en", + debug: true, + + interpolation: { + escapeValue: false, + }, + + // react i18next special options (optional) + // override if needed - omit if ok with defaults + /* + react: { + bindI18n: 'languageChanged', + bindI18nStore: '', + transEmptyNodeValue: '', + transSupportBasicHtmlNodes: true, + transKeepBasicHtmlNodesFor: ['br', 'strong', 'i'], + useSuspense: true, + } + */ + }); + +export { i18n }; diff --git a/apps/frontend/app/layout.tsx b/apps/frontend/app/layout.tsx index c2ff57351..211635c11 100644 --- a/apps/frontend/app/layout.tsx +++ b/apps/frontend/app/layout.tsx @@ -1,3 +1,5 @@ +import { I18nextProvider } from "react-i18next"; +import { i18n } from "./i18n"; import globalFontsVariables from "@/fonts"; import { Analytics } from "@vercel/analytics/react"; import { cx } from "cva"; @@ -15,7 +17,8 @@ export default async function RootLayout({ children: React.ReactNode; }) { return ( - + +