From 2eea98de5cee1edc346787f01972456c778755af Mon Sep 17 00:00:00 2001 From: timothycarambat Date: Wed, 8 May 2024 17:20:14 -0700 Subject: [PATCH 01/15] Init support of i18n and English and mandarin --- frontend/package.json | 3 + frontend/src/App.jsx | 196 +++++++++--------- .../Modals/Password/MultiUserAuth.jsx | 9 +- .../Modals/Password/SingleUserAuth.jsx | 6 +- .../src/components/SettingsSidebar/index.jsx | 44 ++-- frontend/src/i18n.js | 20 ++ frontend/src/locales/en/common.js | 34 +++ frontend/src/locales/resources.js | 12 ++ frontend/src/locales/zh/common.js | 35 ++++ frontend/yarn.lock | 41 ++++ 10 files changed, 279 insertions(+), 121 deletions(-) create mode 100644 frontend/src/i18n.js create mode 100644 frontend/src/locales/en/common.js create mode 100644 frontend/src/locales/resources.js create mode 100644 frontend/src/locales/zh/common.js diff --git a/frontend/package.json b/frontend/package.json index ded06aa9c77..7d084bec66d 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -19,6 +19,8 @@ "file-saver": "^2.0.5", "he": "^1.2.0", "highlight.js": "^11.9.0", + "i18next": "^23.11.3", + "i18next-browser-languagedetector": "^7.2.1", "lodash.debounce": "^4.0.8", "markdown-it": "^13.0.1", "pluralize": "^8.0.0", @@ -26,6 +28,7 @@ "react-device-detect": "^2.2.2", "react-dom": "^18.2.0", "react-dropzone": "^14.2.3", + "react-i18next": "^14.1.1", "react-loading-skeleton": "^3.1.0", "react-router-dom": "^6.3.0", "react-tag-input-component": "^2.0.2", diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 0a5ed65fc85..61493fb356e 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -1,5 +1,6 @@ import React, { lazy, Suspense } from "react"; import { Routes, Route } from "react-router-dom"; +import { I18nextProvider } from "react-i18next"; import { ContextWrapper } from "@/AuthContext"; import PrivateRoute, { AdminRoute, @@ -9,6 +10,7 @@ import { ToastContainer } from "react-toastify"; import "react-toastify/dist/ReactToastify.css"; import Login from "@/pages/Login"; import OnboardingFlow from "@/pages/OnboardingFlow"; +import i18n from "./i18n"; import { PfpProvider } from "./PfpContext"; import { LogoProvider } from "./LogoContext"; @@ -57,102 +59,106 @@ export default function App() { - - } /> - } /> - } - /> - } - /> - } - /> - } /> + + + } /> + } /> + } + /> + } + /> + } + /> + } /> - {/* Admin */} - } - /> - - } - /> - } - /> - - } - /> - } - /> - } - /> - } - /> - } - /> - {/* Manager */} - } - /> - } - /> - } - /> - } - /> - } - /> - } - /> - } - /> - } - /> - } - /> - {/* Onboarding Flow */} - } /> - } /> - - + {/* Admin */} + } + /> + + } + /> + + } + /> + + } + /> + } + /> + } + /> + } + /> + } + /> + {/* Manager */} + } + /> + } + /> + } + /> + } + /> + } + /> + } + /> + } + /> + } + /> + } + /> + {/* Onboarding Flow */} + } /> + } /> + + + diff --git a/frontend/src/components/Modals/Password/MultiUserAuth.jsx b/frontend/src/components/Modals/Password/MultiUserAuth.jsx index e4de5e67e28..f6888fc2bf1 100644 --- a/frontend/src/components/Modals/Password/MultiUserAuth.jsx +++ b/frontend/src/components/Modals/Password/MultiUserAuth.jsx @@ -6,6 +6,7 @@ import showToast from "@/utils/toast"; import ModalWrapper from "@/components/ModalWrapper"; import { useModal } from "@/hooks/useModal"; import RecoveryCodeModal from "@/components/Modals/DisplayRecoveryCodeModal"; +import { useTranslation } from "react-i18next"; const RecoveryForm = ({ onSubmit, setShowRecoveryForm }) => { const [username, setUsername] = useState(""); @@ -160,6 +161,7 @@ const ResetPasswordForm = ({ onSubmit }) => { }; export default function MultiUserAuth() { + const { t } = useTranslation(); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [recoveryCodes, setRecoveryCodes] = useState([]); @@ -269,14 +271,14 @@ export default function MultiUserAuth() {

- Welcome to + {t("login.multi-user.welcome")}

AnythingLLM

- Sign in to your AnythingLLM account. + {t("login.sign-in")}

@@ -318,7 +320,8 @@ export default function MultiUserAuth() { className="text-white text-sm flex gap-x-1 hover:text-[#46C8FF] hover:underline" onClick={handleResetPassword} > - Forgot password?Reset + {t("login.multi-user.forgot-pass")}? + {t("login.multi-user.reset")} diff --git a/frontend/src/components/Modals/Password/SingleUserAuth.jsx b/frontend/src/components/Modals/Password/SingleUserAuth.jsx index c1f328ba2ca..f55914f46b6 100644 --- a/frontend/src/components/Modals/Password/SingleUserAuth.jsx +++ b/frontend/src/components/Modals/Password/SingleUserAuth.jsx @@ -6,8 +6,10 @@ import paths from "../../../utils/paths"; import ModalWrapper from "@/components/ModalWrapper"; import { useModal } from "@/hooks/useModal"; import RecoveryCodeModal from "@/components/Modals/DisplayRecoveryCodeModal"; +import { useTranslation } from "react-i18next"; export default function SingleUserAuth() { + const { t } = useTranslation(); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const { logo: _initLogo } = useLogo(); @@ -65,14 +67,14 @@ export default function SingleUserAuth() {

- Welcome to + {t("login.multi-user.welcome")}

AnythingLLM

- Sign in to your AnythingLLM instance. + {t("login.sign-in")}

diff --git a/frontend/src/components/SettingsSidebar/index.jsx b/frontend/src/components/SettingsSidebar/index.jsx index 67797d26619..3ac26c1e26f 100644 --- a/frontend/src/components/SettingsSidebar/index.jsx +++ b/frontend/src/components/SettingsSidebar/index.jsx @@ -27,8 +27,10 @@ import { USER_BACKGROUND_COLOR } from "@/utils/constants"; import { isMobile } from "react-device-detect"; import Footer from "../Footer"; import { Link } from "react-router-dom"; +import { useTranslation } from "react-i18next"; export default function SettingsSidebar() { + const { t } = useTranslation(); const { logo } = useLogo(); const { user } = useUser(); const sidebarRef = useRef(null); @@ -111,7 +113,7 @@ export default function SettingsSidebar() {
- +