From 0ca8ee17bed49a94bf215321cd6fba1a605c8ac4 Mon Sep 17 00:00:00 2001 From: JiPai Date: Fri, 8 Nov 2024 01:32:46 +0800 Subject: [PATCH 01/11] feat(i18n): add i18n support --- .../settings/profile/profile-form.tsx | 6 +- apps/dokploy/next-i18next.config.js | 9 ++ apps/dokploy/package.json | 3 + apps/dokploy/pages/_app.tsx | 4 +- .../pages/dashboard/settings/profile.tsx | 4 + apps/dokploy/public/locales/en/common.json | 9 ++ .../public/locales/zh-Hans/common.json | 9 ++ apps/dokploy/utils/i18n.ts | 6 ++ pnpm-lock.yaml | 97 +++++++++++++++++++ 9 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 apps/dokploy/next-i18next.config.js create mode 100644 apps/dokploy/public/locales/en/common.json create mode 100644 apps/dokploy/public/locales/zh-Hans/common.json create mode 100644 apps/dokploy/utils/i18n.ts diff --git a/apps/dokploy/components/dashboard/settings/profile/profile-form.tsx b/apps/dokploy/components/dashboard/settings/profile/profile-form.tsx index 3c8d51bb9..799227001 100644 --- a/apps/dokploy/components/dashboard/settings/profile/profile-form.tsx +++ b/apps/dokploy/components/dashboard/settings/profile/profile-form.tsx @@ -18,6 +18,7 @@ import { Input } from "@/components/ui/input"; import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; import { api } from "@/utils/api"; import { zodResolver } from "@hookform/resolvers/zod"; +import { useTranslation } from "next-i18next"; import { useEffect } from "react"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; @@ -51,6 +52,7 @@ const randomImages = [ export const ProfileForm = () => { const { data, refetch } = api.auth.get.useQuery(); const { mutateAsync, isLoading } = api.auth.update.useMutation(); + const { t } = useTranslation("common"); const form = useForm({ defaultValues: { @@ -91,7 +93,9 @@ export const ProfileForm = () => {
- Account + + {t("dashboard.settings.profile.title")} + Change the details of your profile here. diff --git a/apps/dokploy/next-i18next.config.js b/apps/dokploy/next-i18next.config.js new file mode 100644 index 000000000..7e365819d --- /dev/null +++ b/apps/dokploy/next-i18next.config.js @@ -0,0 +1,9 @@ +/** @type {import('next-i18next').UserConfig} */ +module.exports = { + i18n: { + defaultLocale: "en", + locales: ["en", "zh-Hans"], + localeDetection: false, + }, + fallbackLng: "en", +}; diff --git a/apps/dokploy/package.json b/apps/dokploy/package.json index e62bb1dd8..9a281b796 100644 --- a/apps/dokploy/package.json +++ b/apps/dokploy/package.json @@ -84,6 +84,7 @@ "dotenv": "16.4.5", "drizzle-orm": "^0.30.8", "drizzle-zod": "0.5.1", + "i18next": "^23.16.4", "input-otp": "^1.2.4", "js-yaml": "4.1.0", "lodash": "4.17.21", @@ -91,6 +92,7 @@ "lucide-react": "^0.312.0", "nanoid": "3", "next": "^15.0.1", + "next-i18next": "^15.3.1", "next-themes": "^0.2.1", "node-pty": "1.0.0", "node-schedule": "2.1.1", @@ -100,6 +102,7 @@ "react": "18.2.0", "react-dom": "18.2.0", "react-hook-form": "^7.49.3", + "react-i18next": "^15.1.0", "recharts": "^2.12.7", "slugify": "^1.6.6", "sonner": "^1.4.0", diff --git a/apps/dokploy/pages/_app.tsx b/apps/dokploy/pages/_app.tsx index 41b4d50bf..c8e00aca5 100644 --- a/apps/dokploy/pages/_app.tsx +++ b/apps/dokploy/pages/_app.tsx @@ -3,6 +3,7 @@ import "@/styles/globals.css"; import { Toaster } from "@/components/ui/sonner"; import { api } from "@/utils/api"; import type { NextPage } from "next"; +import { appWithTranslation } from "next-i18next"; import { ThemeProvider } from "next-themes"; import type { AppProps } from "next/app"; import { Inter } from "next/font/google"; @@ -27,6 +28,7 @@ const MyApp = ({ pageProps: { ...pageProps }, }: AppPropsWithLayout) => { const getLayout = Component.getLayout ?? ((page) => page); + return ( <>