Skip to content

Commit

Permalink
feat: Add setup file
Browse files Browse the repository at this point in the history
  • Loading branch information
codemod[bot] committed Dec 20, 2024
1 parent 39309a3 commit df20f6b
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 3 deletions.
47 changes: 47 additions & 0 deletions apps/frontend/app/i18n.ts
Original file line number Diff line number Diff line change
@@ -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 };
6 changes: 5 additions & 1 deletion apps/frontend/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -15,7 +17,8 @@ export default async function RootLayout({
children: React.ReactNode;
}) {
return (
<html lang="en" className={cx(globalFontsVariables, "scroll-smooth light")}>
<I18nextProvider i18n={i18n}>
<html lang="en" className={cx(globalFontsVariables, "scroll-smooth light")}>
<head>
<Script id="gtm">
{`(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
Expand Down Expand Up @@ -46,5 +49,6 @@ export default async function RootLayout({
<Analytics />
</body>
</html>
</I18nextProvider>
);
}
9 changes: 8 additions & 1 deletion apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
"prepare": "husky"
},
"browserslist": {
"production": [">0.2%", "not dead", "not op_mini all"],
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
Expand Down Expand Up @@ -91,6 +95,8 @@
"fuse.js": "catalog:",
"geist": "^1.3.1",
"get-youtube-id": "catalog:",
"i18next": "^24.1.0",
"i18next-browser-languagedetector": "^8.0.2",
"intro.js": "catalog:",
"intro.js-react": "catalog:",
"js-beautify": "catalog:",
Expand All @@ -117,6 +123,7 @@
"react-dom": "18.2.0",
"react-hook-form": "catalog:",
"react-hot-toast": "catalog:",
"react-i18next": "^15.2.0",
"react-markdown": "catalog:",
"react-resizable-panels": "^2.0.15",
"react-syntax-highlighter": "catalog:",
Expand Down
9 changes: 8 additions & 1 deletion apps/vsce/webview/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
"@vscode/webview-ui-toolkit": "catalog:",
"classnames": "^2.3.2",
"fp-ts": "^2.14.0",
"i18next": "^24.1.0",
"i18next-browser-languagedetector": "^8.0.2",
"lowlight": "catalog:",
"monaco-editor": "^0.37.1",
"preact": "catalog:",
"preact-compat": "catalog:",
"rc-progress": "catalog:",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-i18next": "^15.2.0",
"react-resizable-panels": "^0.0.51",
"react-toastify": "catalog:",
"tippy.js": "catalog:",
Expand All @@ -32,7 +35,11 @@
"build:webview": "pnpm build:main && pnpm build:jobDiffView && pnpm build:errors"
},
"browserslist": {
"production": [">0.2%", "not dead", "not op_mini all"],
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
Expand Down
47 changes: 47 additions & 0 deletions apps/vsce/webview/src/main/i18n.ts
Original file line number Diff line number Diff line change
@@ -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 };
2 changes: 2 additions & 0 deletions apps/vsce/webview/src/main/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { I18nextProvider } from "react-i18next";
import { i18n } from "./i18n";
import React from "react";
import ReactDOM from "react-dom/client";
import "tippy.js/dist/tippy.css";
Expand Down

0 comments on commit df20f6b

Please sign in to comment.