feat: Load automatic language settings on app startup
This commit is contained in:
1 parent
a72d0029a1
commit
a549e42c43
3 files changed
+15
-3
No files matched your search
+13
-2
@@ -12,17 +12,28 @@ 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 { authToken } = useSelector((state) => state.auth);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
const { i18n } = useTranslation();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (authToken) {
|
if (authToken) {
|
||||||
dispatch(getAppSettings({ authToken }));
|
dispatch(getAppSettings({ authToken })).then((action) => {
|
||||||
|
if (action.payload && action.payload.success) {
|
||||||
|
const { language } = action.payload.data;
|
||||||
|
if (language) {
|
||||||
|
dispatch(setLanguage(language));
|
||||||
|
i18n.changeLanguage(language);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}, [dispatch, authToken]);
|
}, [dispatch, authToken, i18n]);
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ const LanguageSelector = () => {
|
|||||||
i18n.changeLanguage(newLang);
|
i18n.changeLanguage(newLang);
|
||||||
};
|
};
|
||||||
|
|
||||||
// i18n instance'ından mevcut dilleri al
|
|
||||||
const languages = Object.keys(i18n.options.resources || {});
|
const languages = Object.keys(i18n.options.resources || {});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const initialState = {
|
|||||||
isLoading: false,
|
isLoading: false,
|
||||||
apiBaseUrl: "",
|
apiBaseUrl: "",
|
||||||
logLevel: "debug",
|
logLevel: "debug",
|
||||||
|
language: "",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getAppSettings = createAsyncThunk(
|
export const getAppSettings = createAsyncThunk(
|
||||||
@@ -69,6 +70,7 @@ const handleGetSettingsFulfilled = (state, action) => {
|
|||||||
state.msg = action.payload.msg;
|
state.msg = action.payload.msg;
|
||||||
state.apiBaseUrl = action.payload.data.apiBaseUrl;
|
state.apiBaseUrl = action.payload.data.apiBaseUrl;
|
||||||
state.logLevel = action.payload.data.logLevel;
|
state.logLevel = action.payload.data.logLevel;
|
||||||
|
state.language = action.payload.data.language;
|
||||||
};
|
};
|
||||||
const handleGetSettingsRejected = (state, action) => {
|
const handleGetSettingsRejected = (state, action) => {
|
||||||
state.isLoading = false;
|
state.isLoading = false;
|
||||||
|
|||||||
Reference in new issue
Block a user