This commit is contained in:
josc146 2023-05-18 21:32:02 +08:00
parent 934f7b15e8
commit 18db41fd76
5 changed files with 12 additions and 9 deletions

View File

@ -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());
});

View File

@ -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());
});

View File

@ -17,7 +17,7 @@ export const Settings: FC = observer(() => {
<Labeled label={t('Language')} flex spaceBetween content={
<Dropdown style={{minWidth: 0}} listbox={{style: {minWidth: 0}}}
value={Languages[commonStore.settings.language]}
selectedOptions={[Languages[commonStore.settings.language]]}
selectedOptions={[commonStore.settings.language]}
onOptionSelect={(_, data) => {
if (data.optionValue) {
const lang = data.optionValue as Language;

View File

@ -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
};

View File

@ -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() {