diff --git a/frontend/src/_locales/i18n-react.ts b/frontend/src/_locales/i18n-react.ts index de8e3b4..8e6d557 100644 --- a/frontend/src/_locales/i18n-react.ts +++ b/frontend/src/_locales/i18n-react.ts @@ -1,7 +1,7 @@ import i18n, {changeLanguage} from 'i18next'; import {initReactI18next} from 'react-i18next'; import {resources} from './resources'; -import {getNavigatorLanguage} from '../utils'; +import {getUserLanguage} from '../utils'; i18n.use(initReactI18next).init({ resources, @@ -9,5 +9,5 @@ i18n.use(initReactI18next).init({ escapeValue: false // not needed for react as it escapes by default } }).then(() => { - changeLanguage(getNavigatorLanguage()); + changeLanguage(getUserLanguage()); }); diff --git a/frontend/src/_locales/i18n.ts b/frontend/src/_locales/i18n.ts index 34ed77c..a5c5e4e 100644 --- a/frontend/src/_locales/i18n.ts +++ b/frontend/src/_locales/i18n.ts @@ -1,9 +1,9 @@ import i18n, {changeLanguage} from 'i18next'; import {resources} from './resources'; -import {getNavigatorLanguage} from '../utils'; +import {getUserLanguage} from '../utils'; i18n.init({ resources }).then(() => { - changeLanguage(getNavigatorLanguage()); + changeLanguage(getUserLanguage()); }); diff --git a/frontend/src/pages/Settings.tsx b/frontend/src/pages/Settings.tsx index f68157b..7c08dac 100644 --- a/frontend/src/pages/Settings.tsx +++ b/frontend/src/pages/Settings.tsx @@ -17,7 +17,7 @@ export const Settings: FC = observer(() => { { if (data.optionValue) { const lang = data.optionValue as Language; diff --git a/frontend/src/stores/commonStore.ts b/frontend/src/stores/commonStore.ts index 8b7d704..8c9c87c 100644 --- a/frontend/src/stores/commonStore.ts +++ b/frontend/src/stores/commonStore.ts @@ -1,5 +1,5 @@ import {makeAutoObservable} from 'mobx'; -import {getNavigatorLanguage, isSystemLightMode, Language, saveConfigs, Settings} from '../utils'; +import {getUserLanguage, isSystemLightMode, saveConfigs, Settings} from '../utils'; import {WindowSetDarkTheme, WindowSetLightTheme} from '../../wailsjs/runtime'; export enum ModelStatus { @@ -84,7 +84,7 @@ class CommonStore { modelSourceManifestList: string = 'https://cdn.jsdelivr.net/gh/josstorer/RWKV-Runner/manifest.json;'; modelSourceList: ModelSourceItem[] = []; settings: Settings = { - language: getNavigatorLanguage() as Language, + language: getUserLanguage(), darkMode: !isSystemLightMode(), autoUpdatesCheck: true }; diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts index ab736b4..696dc42 100644 --- a/frontend/src/utils/index.ts +++ b/frontend/src/utils/index.ts @@ -149,10 +149,13 @@ export const saveCache = async () => { return SaveJson('cache.json', data); }; -export function getNavigatorLanguage() { +export function getUserLanguage(): Language { // const l = navigator.language.toLowerCase(); // if (['zh-hk', 'zh-mo', 'zh-tw', 'zh-cht', 'zh-hant'].includes(l)) return 'zhHant' - return navigator.language.substring(0, 2); + + const l = navigator.language.substring(0, 2); + if (l in Languages) return l as Language; + return 'dev'; } export function isSystemLightMode() {