mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-05-21 17:19:00 -05:00
Merge pull request #2200 from Cihatata/fix/language-detection
Fix/language detection
This commit is contained in:
@@ -13,9 +13,6 @@ on:
|
||||
required: false
|
||||
default: "key_value_json"
|
||||
|
||||
# For automatic execution at a specific time (every day at midnight)
|
||||
schedule:
|
||||
- cron: "0 0 * * *"
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
@@ -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(() => {
|
||||
|
||||
@@ -5,7 +5,7 @@ const initialState = {
|
||||
isLoading: false,
|
||||
apiBaseUrl: "",
|
||||
logLevel: "debug",
|
||||
language: "",
|
||||
language: "gb",
|
||||
};
|
||||
|
||||
export const getAppSettings = createAsyncThunk(
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -32,7 +32,7 @@ class NetworkService {
|
||||
|
||||
config.headers = {
|
||||
Authorization: `Bearer ${authToken}`,
|
||||
"Accept-Language": currentLanguage,
|
||||
"Accept-Language": currentLanguage === "gb" ? "en" : currentLanguage,
|
||||
...config.headers,
|
||||
};
|
||||
|
||||
@@ -924,7 +924,7 @@ class NetworkService {
|
||||
onOpen?.();
|
||||
};
|
||||
|
||||
this.eventSource.addEventListener("open", (e) => {});
|
||||
this.eventSource.addEventListener("open", (e) => { });
|
||||
|
||||
this.eventSource.onmessage = (event) => {
|
||||
const data = JSON.parse(event.data);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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",
|
||||
@@ -413,3 +414,4 @@
|
||||
},
|
||||
"publicLink": "Public link"
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
"createAPassword": "Создайте пароль",
|
||||
"authRegisterAlreadyHaveAccount": "Уже есть аккаунт?",
|
||||
"commonAppName": "Checkmate",
|
||||
"welcomeBack": "Добро пожаловать обратно! Вы успешно вошли в систему.",
|
||||
"authLoginEnterEmail": "Введите свой email",
|
||||
"authRegisterTitle": "Создать аккаунт",
|
||||
"authRegisterStepOneTitle": "Создайте свой аккаут",
|
||||
@@ -368,4 +369,4 @@
|
||||
"pageSpeedWarning": "Предупреждение: Вы не добавили ключ API Google PageSpeed. Без него монитор PageSpeed не будет работать.",
|
||||
"pageSpeedLearnMoreLink": "Нажмите здесь, чтобы узнать",
|
||||
"pageSpeedAddApiKey": "как добавить ваш ключ API."
|
||||
}
|
||||
}
|
||||
@@ -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",
|
||||
|
||||
@@ -7,10 +7,6 @@ const AppSettingsSchema = mongoose.Schema(
|
||||
required: true,
|
||||
default: "http://localhost:5000/api/v1",
|
||||
},
|
||||
language: {
|
||||
type: String,
|
||||
default: "en",
|
||||
},
|
||||
logLevel: {
|
||||
type: String,
|
||||
default: "debug",
|
||||
|
||||
@@ -1,16 +1,10 @@
|
||||
import logger from "../utils/logger.js";
|
||||
|
||||
const languageMiddleware =
|
||||
(stringService, translationService, settingsService) => async (req, res, next) => {
|
||||
(stringService, translationService) => async (req, res, next) => {
|
||||
try {
|
||||
const settings = await settingsService.getSettings();
|
||||
|
||||
let language = settings && settings.language ? settings.language : null;
|
||||
|
||||
if (!language) {
|
||||
const acceptLanguage = req.headers["accept-language"] || "en";
|
||||
language = acceptLanguage.split(",")[0].slice(0, 2).toLowerCase();
|
||||
}
|
||||
const acceptLanguage = req.headers["accept-language"] || "en";
|
||||
const language = acceptLanguage.split(",")[0].slice(0, 2).toLowerCase();
|
||||
|
||||
translationService.setLanguage(language);
|
||||
stringService.setLanguage(language);
|
||||
|
||||
@@ -3,7 +3,6 @@ import dotenv from "dotenv";
|
||||
dotenv.config();
|
||||
const envConfig = {
|
||||
logLevel: process.env.LOG_LEVEL,
|
||||
language: process.env.LANGUAGE,
|
||||
clientHost: process.env.CLIENT_HOST,
|
||||
jwtSecret: process.env.JWT_SECRET,
|
||||
dbType: process.env.DB_TYPE,
|
||||
|
||||
Reference in New Issue
Block a user