Merge pull request #2200 from Cihatata/fix/language-detection
Fix/language detection
This commit is contained in:
12 files changed
+20
-49
No files matched your search
@@ -13,9 +13,6 @@ on:
|
|||||||
required: false
|
required: false
|
||||||
default: "key_value_json"
|
default: "key_value_json"
|
||||||
|
|
||||||
# For automatic execution at a specific time (every day at midnight)
|
|
||||||
schedule:
|
|
||||||
- cron: "0 0 * * *"
|
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
|
|||||||
@@ -1,43 +1,18 @@
|
|||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import { useDispatch } from "react-redux";
|
|
||||||
import "react-toastify/dist/ReactToastify.css";
|
import "react-toastify/dist/ReactToastify.css";
|
||||||
import { ToastContainer } from "react-toastify";
|
import { ToastContainer } from "react-toastify";
|
||||||
import { ThemeProvider } from "@emotion/react";
|
import { ThemeProvider } from "@emotion/react";
|
||||||
import lightTheme from "./Utils/Theme/lightTheme";
|
import lightTheme from "./Utils/Theme/lightTheme";
|
||||||
import darkTheme from "./Utils/Theme/darkTheme";
|
import darkTheme from "./Utils/Theme/darkTheme";
|
||||||
import { CssBaseline, GlobalStyles } from "@mui/material";
|
import { CssBaseline, GlobalStyles } from "@mui/material";
|
||||||
import { getAppSettings } from "./Features/Settings/settingsSlice";
|
|
||||||
import { logger } from "./Utils/Logger"; // Import the logger
|
import { logger } from "./Utils/Logger"; // Import the logger
|
||||||
import { networkService } from "./main";
|
import { networkService } from "./main";
|
||||||
import { Routes } from "./Routes";
|
import { Routes } from "./Routes";
|
||||||
import WalletProvider from "./Components/WalletProvider";
|
import WalletProvider from "./Components/WalletProvider";
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { setLanguage } from "./Features/UI/uiSlice";
|
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const mode = useSelector((state) => state.ui.mode);
|
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
|
// Cleanup
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ const initialState = {
|
|||||||
isLoading: false,
|
isLoading: false,
|
||||||
apiBaseUrl: "",
|
apiBaseUrl: "",
|
||||||
logLevel: "debug",
|
logLevel: "debug",
|
||||||
language: "",
|
language: "gb",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getAppSettings = createAsyncThunk(
|
export const getAppSettings = createAsyncThunk(
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import PasswordStep from "./Components/PasswordStep";
|
|||||||
import ThemeSwitch from "../../../Components/ThemeSwitch";
|
import ThemeSwitch from "../../../Components/ThemeSwitch";
|
||||||
import ForgotPasswordLabel from "./Components/ForgotPasswordLabel";
|
import ForgotPasswordLabel from "./Components/ForgotPasswordLabel";
|
||||||
import LanguageSelector from "../../../Components/LanguageSelector";
|
import LanguageSelector from "../../../Components/LanguageSelector";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
const DEMO = import.meta.env.VITE_APP_DEMO;
|
const DEMO = import.meta.env.VITE_APP_DEMO;
|
||||||
|
|
||||||
@@ -27,6 +28,7 @@ const Login = () => {
|
|||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const authState = useSelector((state) => state.auth);
|
const authState = useSelector((state) => state.auth);
|
||||||
const { authToken } = authState;
|
const { authToken } = authState;
|
||||||
@@ -63,13 +65,17 @@ const Login = () => {
|
|||||||
const handleChange = (event) => {
|
const handleChange = (event) => {
|
||||||
const { value, id } = event.target;
|
const { value, id } = event.target;
|
||||||
const name = idMap[id];
|
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) => ({
|
setForm((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
[name]: lowerCasedValue,
|
[name]: lowerCasedValue,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const { error } = credentials.validate({ [name]: lowerCasedValue }, { abortEarly: false });
|
const { error } = credentials.validate(
|
||||||
|
{ [name]: lowerCasedValue },
|
||||||
|
{ abortEarly: false }
|
||||||
|
);
|
||||||
|
|
||||||
setErrors((prev) => {
|
setErrors((prev) => {
|
||||||
const prevErrors = { ...prev };
|
const prevErrors = { ...prev };
|
||||||
@@ -114,7 +120,7 @@ const Login = () => {
|
|||||||
if (action.payload.success) {
|
if (action.payload.success) {
|
||||||
navigate("/uptime");
|
navigate("/uptime");
|
||||||
createToast({
|
createToast({
|
||||||
body: "Welcome back! You're successfully logged in.",
|
body: t("welcomeBack"),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (action.payload) {
|
if (action.payload) {
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class NetworkService {
|
|||||||
|
|
||||||
config.headers = {
|
config.headers = {
|
||||||
Authorization: `Bearer ${authToken}`,
|
Authorization: `Bearer ${authToken}`,
|
||||||
"Accept-Language": currentLanguage,
|
"Accept-Language": currentLanguage === "gb" ? "en" : currentLanguage,
|
||||||
...config.headers,
|
...config.headers,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -924,7 +924,7 @@ class NetworkService {
|
|||||||
onOpen?.();
|
onOpen?.();
|
||||||
};
|
};
|
||||||
|
|
||||||
this.eventSource.addEventListener("open", (e) => {});
|
this.eventSource.addEventListener("open", (e) => { });
|
||||||
|
|
||||||
this.eventSource.onmessage = (event) => {
|
this.eventSource.onmessage = (event) => {
|
||||||
const data = JSON.parse(event.data);
|
const data = JSON.parse(event.data);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ Object.keys(translations).forEach((path) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const savedLanguage = store.getState()?.ui?.language;
|
const savedLanguage = store.getState()?.ui?.language;
|
||||||
const initialLanguage = savedLanguage || primaryLanguage;
|
const initialLanguage = savedLanguage;
|
||||||
|
|
||||||
i18n.use(initReactI18next).init({
|
i18n.use(initReactI18next).init({
|
||||||
resources,
|
resources,
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
"createAPassword": "Create a password",
|
"createAPassword": "Create a password",
|
||||||
"authRegisterAlreadyHaveAccount": "Already have an account?",
|
"authRegisterAlreadyHaveAccount": "Already have an account?",
|
||||||
"commonAppName": "Checkmate",
|
"commonAppName": "Checkmate",
|
||||||
|
"welcomeBack": "Welcome back! You're successfully logged in.",
|
||||||
"authLoginEnterEmail": "Enter your email",
|
"authLoginEnterEmail": "Enter your email",
|
||||||
"authRegisterTitle": "Create an account",
|
"authRegisterTitle": "Create an account",
|
||||||
"authRegisterStepOneTitle": "Create your account",
|
"authRegisterStepOneTitle": "Create your account",
|
||||||
@@ -413,3 +414,4 @@
|
|||||||
},
|
},
|
||||||
"publicLink": "Public link"
|
"publicLink": "Public link"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
"createAPassword": "Создайте пароль",
|
"createAPassword": "Создайте пароль",
|
||||||
"authRegisterAlreadyHaveAccount": "Уже есть аккаунт?",
|
"authRegisterAlreadyHaveAccount": "Уже есть аккаунт?",
|
||||||
"commonAppName": "Checkmate",
|
"commonAppName": "Checkmate",
|
||||||
|
"welcomeBack": "Добро пожаловать обратно! Вы успешно вошли в систему.",
|
||||||
"authLoginEnterEmail": "Введите свой email",
|
"authLoginEnterEmail": "Введите свой email",
|
||||||
"authRegisterTitle": "Создать аккаунт",
|
"authRegisterTitle": "Создать аккаунт",
|
||||||
"authRegisterStepOneTitle": "Создайте свой аккаут",
|
"authRegisterStepOneTitle": "Создайте свой аккаут",
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
"createAPassword": "Bir parola oluşturun",
|
"createAPassword": "Bir parola oluşturun",
|
||||||
"authRegisterAlreadyHaveAccount": "Zaten hesabınız var mı?",
|
"authRegisterAlreadyHaveAccount": "Zaten hesabınız var mı?",
|
||||||
"commonAppName": "Checkmate",
|
"commonAppName": "Checkmate",
|
||||||
|
"welcomeBack": "Tekrar hoş geldiniz! Başarıyla giriş yaptınız.",
|
||||||
"authLoginEnterEmail": "E-posta adresinizi girin",
|
"authLoginEnterEmail": "E-posta adresinizi girin",
|
||||||
"authRegisterTitle": "Hesap oluştur",
|
"authRegisterTitle": "Hesap oluştur",
|
||||||
"authRegisterStepOneTitle": "Hesabınızı oluşturun",
|
"authRegisterStepOneTitle": "Hesabınızı oluşturun",
|
||||||
|
|||||||
@@ -7,10 +7,6 @@ const AppSettingsSchema = mongoose.Schema(
|
|||||||
required: true,
|
required: true,
|
||||||
default: "http://localhost:5000/api/v1",
|
default: "http://localhost:5000/api/v1",
|
||||||
},
|
},
|
||||||
language: {
|
|
||||||
type: String,
|
|
||||||
default: "en",
|
|
||||||
},
|
|
||||||
logLevel: {
|
logLevel: {
|
||||||
type: String,
|
type: String,
|
||||||
default: "debug",
|
default: "debug",
|
||||||
|
|||||||
@@ -1,16 +1,10 @@
|
|||||||
import logger from "../utils/logger.js";
|
import logger from "../utils/logger.js";
|
||||||
|
|
||||||
const languageMiddleware =
|
const languageMiddleware =
|
||||||
(stringService, translationService, settingsService) => async (req, res, next) => {
|
(stringService, translationService) => async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const settings = await settingsService.getSettings();
|
const acceptLanguage = req.headers["accept-language"] || "en";
|
||||||
|
const language = acceptLanguage.split(",")[0].slice(0, 2).toLowerCase();
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
translationService.setLanguage(language);
|
translationService.setLanguage(language);
|
||||||
stringService.setLanguage(language);
|
stringService.setLanguage(language);
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import dotenv from "dotenv";
|
|||||||
dotenv.config();
|
dotenv.config();
|
||||||
const envConfig = {
|
const envConfig = {
|
||||||
logLevel: process.env.LOG_LEVEL,
|
logLevel: process.env.LOG_LEVEL,
|
||||||
language: process.env.LANGUAGE,
|
|
||||||
clientHost: process.env.CLIENT_HOST,
|
clientHost: process.env.CLIENT_HOST,
|
||||||
jwtSecret: process.env.JWT_SECRET,
|
jwtSecret: process.env.JWT_SECRET,
|
||||||
dbType: process.env.DB_TYPE,
|
dbType: process.env.DB_TYPE,
|
||||||
|
|||||||
Reference in new issue
Block a user