diff --git a/client/src/App.jsx b/client/src/App.jsx index 1d5709847..7fb63ee61 100644 --- a/client/src/App.jsx +++ b/client/src/App.jsx @@ -1,43 +1,18 @@ import { useEffect } from "react"; import { useSelector } from "react-redux"; -import { useDispatch } from "react-redux"; import "react-toastify/dist/ReactToastify.css"; import { ToastContainer } from "react-toastify"; import { ThemeProvider } from "@emotion/react"; import lightTheme from "./Utils/Theme/lightTheme"; import darkTheme from "./Utils/Theme/darkTheme"; import { CssBaseline, GlobalStyles } from "@mui/material"; -import { getAppSettings } from "./Features/Settings/settingsSlice"; import { logger } from "./Utils/Logger"; // Import the logger import { networkService } from "./main"; import { Routes } from "./Routes"; import WalletProvider from "./Components/WalletProvider"; -import { useTranslation } from "react-i18next"; -import { setLanguage } from "./Features/UI/uiSlice"; function App() { const mode = useSelector((state) => state.ui.mode); - const { authToken } = useSelector((state) => state.auth); - const dispatch = useDispatch(); - const { i18n } = useTranslation(); - - useEffect(() => { - if (authToken) { - dispatch(getAppSettings({ authToken })).then((action) => { - if (action.payload && action.payload.success) { - const { language } = action.payload.data; - const availableLanguages = Object.keys(i18n.options.resources || {}); - if (language && availableLanguages.includes(language)) { - dispatch(setLanguage(language)); - i18n.changeLanguage(language); - } else { - dispatch(setLanguage(availableLanguages[0])); - i18n.changeLanguage(availableLanguages[0]); - } - } - }); - } - }, [dispatch, authToken, i18n]); // Cleanup useEffect(() => { diff --git a/client/src/Features/UI/uiSlice.js b/client/src/Features/UI/uiSlice.js index f20115b92..1fc2f865d 100644 --- a/client/src/Features/UI/uiSlice.js +++ b/client/src/Features/UI/uiSlice.js @@ -23,7 +23,7 @@ const initialState = { greeting: { index: 0, lastUpdate: null }, timezone: "America/Toronto", distributedUptimeEnabled: false, - language: "gb", + language: localStorage.getItem("app_language") || "gb", starPromptOpen: true, }; diff --git a/client/src/Pages/Auth/Login/Login.jsx b/client/src/Pages/Auth/Login/Login.jsx index 9db56ae49..1337a8723 100644 --- a/client/src/Pages/Auth/Login/Login.jsx +++ b/client/src/Pages/Auth/Login/Login.jsx @@ -16,6 +16,7 @@ import PasswordStep from "./Components/PasswordStep"; import ThemeSwitch from "../../../Components/ThemeSwitch"; import ForgotPasswordLabel from "./Components/ForgotPasswordLabel"; import LanguageSelector from "../../../Components/LanguageSelector"; +import { useTranslation } from "react-i18next"; const DEMO = import.meta.env.VITE_APP_DEMO; @@ -27,6 +28,7 @@ const Login = () => { const dispatch = useDispatch(); const navigate = useNavigate(); const theme = useTheme(); + const { t } = useTranslation(); const authState = useSelector((state) => state.auth); const { authToken } = authState; @@ -63,13 +65,17 @@ const Login = () => { const handleChange = (event) => { const { value, id } = event.target; const name = idMap[id]; - const lowerCasedValue = name === idMap["login-email-input"]? value?.toLowerCase()||value : value + const lowerCasedValue = + name === idMap["login-email-input"] ? value?.toLowerCase() || value : value; setForm((prev) => ({ ...prev, [name]: lowerCasedValue, })); - const { error } = credentials.validate({ [name]: lowerCasedValue }, { abortEarly: false }); + const { error } = credentials.validate( + { [name]: lowerCasedValue }, + { abortEarly: false } + ); setErrors((prev) => { const prevErrors = { ...prev }; @@ -114,7 +120,7 @@ const Login = () => { if (action.payload.success) { navigate("/uptime"); createToast({ - body: "Welcome back! You're successfully logged in.", + body: t("welcomeBack"), }); } else { if (action.payload) { diff --git a/client/src/Utils/NetworkService.js b/client/src/Utils/NetworkService.js index 7c4ffba9f..52e3aae69 100644 --- a/client/src/Utils/NetworkService.js +++ b/client/src/Utils/NetworkService.js @@ -32,7 +32,7 @@ class NetworkService { config.headers = { Authorization: `Bearer ${authToken}`, - "Accept-Language": currentLanguage, + "Accept-Language": currentLanguage === "gb" ? "en" : currentLanguage, ...config.headers, }; @@ -920,7 +920,7 @@ class NetworkService { onOpen?.(); }; - this.eventSource.addEventListener("open", (e) => {}); + this.eventSource.addEventListener("open", (e) => { }); this.eventSource.onmessage = (event) => { const data = JSON.parse(event.data); diff --git a/client/src/Utils/i18n.js b/client/src/Utils/i18n.js index 6243a2599..a2e84f1dc 100644 --- a/client/src/Utils/i18n.js +++ b/client/src/Utils/i18n.js @@ -16,7 +16,7 @@ Object.keys(translations).forEach((path) => { }); const savedLanguage = store.getState()?.ui?.language; -const initialLanguage = savedLanguage || primaryLanguage; +const initialLanguage = savedLanguage; i18n.use(initReactI18next).init({ resources, @@ -32,6 +32,7 @@ i18n.use(initReactI18next).init({ i18n.on("languageChanged", (lng) => { store.dispatch(setLanguage(lng)); + window.localStorage.setItem("app_language", lng); }); export default i18n; diff --git a/client/src/locales/gb.json b/client/src/locales/gb.json index 95ef6d32e..4d5ac89c1 100644 --- a/client/src/locales/gb.json +++ b/client/src/locales/gb.json @@ -18,6 +18,7 @@ "createAPassword": "Create a password", "authRegisterAlreadyHaveAccount": "Already have an account?", "commonAppName": "Checkmate", + "welcomeBack": "Welcome back! You're successfully logged in.", "authLoginEnterEmail": "Enter your email", "authRegisterTitle": "Create an account", "authRegisterStepOneTitle": "Create your account", @@ -396,4 +397,4 @@ "DeleteDescriptionText": "Note that deleting your account will remove all data from the server. This is permanent and non-recoverable.", "DeleteAccountWarning": "If you delete your account, you will no longer be able to sign in, and all of your data will be deleted. Deleting your account is permanent and non-recoverable action.", "DeleteWarningTitle": "Really delete this account?" -} +} \ No newline at end of file diff --git a/client/src/locales/ru.json b/client/src/locales/ru.json index 5d0f649de..76c8c28bd 100644 --- a/client/src/locales/ru.json +++ b/client/src/locales/ru.json @@ -18,6 +18,7 @@ "createAPassword": "Создайте пароль", "authRegisterAlreadyHaveAccount": "Уже есть аккаунт?", "commonAppName": "Checkmate", + "welcomeBack": "Добро пожаловать обратно! Вы успешно вошли в систему.", "authLoginEnterEmail": "Введите свой email", "authRegisterTitle": "Создать аккаунт", "authRegisterStepOneTitle": "Создайте свой аккаут", @@ -364,4 +365,4 @@ "pageSpeedWarning": "Предупреждение: Вы не добавили ключ API Google PageSpeed. Без него монитор PageSpeed не будет работать.", "pageSpeedLearnMoreLink": "Нажмите здесь, чтобы узнать", "pageSpeedAddApiKey": "как добавить ваш ключ API." -} +} \ No newline at end of file diff --git a/client/src/locales/tr.json b/client/src/locales/tr.json index d975d056c..6d89cab94 100644 --- a/client/src/locales/tr.json +++ b/client/src/locales/tr.json @@ -18,6 +18,7 @@ "createAPassword": "Bir parola oluşturun", "authRegisterAlreadyHaveAccount": "Zaten hesabınız var mı?", "commonAppName": "Checkmate", + "welcomeBack": "Tekrar hoş geldiniz! Başarıyla giriş yaptınız.", "authLoginEnterEmail": "E-posta adresinizi girin", "authRegisterTitle": "Hesap oluştur", "authRegisterStepOneTitle": "Hesabınızı oluşturun", @@ -396,4 +397,4 @@ "DeleteDescriptionText": "", "DeleteAccountWarning": "", "DeleteWarningTitle": "" -} +} \ No newline at end of file