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 i18n, {changeLanguage} from 'i18next';
import {initReactI18next} from 'react-i18next'; import {initReactI18next} from 'react-i18next';
import {resources} from './resources'; import {resources} from './resources';
import {getNavigatorLanguage} from '../utils'; import {getUserLanguage} from '../utils';
i18n.use(initReactI18next).init({ i18n.use(initReactI18next).init({
resources, resources,
@ -9,5 +9,5 @@ i18n.use(initReactI18next).init({
escapeValue: false // not needed for react as it escapes by default escapeValue: false // not needed for react as it escapes by default
} }
}).then(() => { }).then(() => {
changeLanguage(getNavigatorLanguage()); changeLanguage(getUserLanguage());
}); });

View File

@ -1,9 +1,9 @@
import i18n, {changeLanguage} from 'i18next'; import i18n, {changeLanguage} from 'i18next';
import {resources} from './resources'; import {resources} from './resources';
import {getNavigatorLanguage} from '../utils'; import {getUserLanguage} from '../utils';
i18n.init({ i18n.init({
resources resources
}).then(() => { }).then(() => {
changeLanguage(getNavigatorLanguage()); changeLanguage(getUserLanguage());
}); });

View File

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

View File

@ -1,5 +1,5 @@
import {makeAutoObservable} from 'mobx'; 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'; import {WindowSetDarkTheme, WindowSetLightTheme} from '../../wailsjs/runtime';
export enum ModelStatus { export enum ModelStatus {
@ -84,7 +84,7 @@ class CommonStore {
modelSourceManifestList: string = 'https://cdn.jsdelivr.net/gh/josstorer/RWKV-Runner/manifest.json;'; modelSourceManifestList: string = 'https://cdn.jsdelivr.net/gh/josstorer/RWKV-Runner/manifest.json;';
modelSourceList: ModelSourceItem[] = []; modelSourceList: ModelSourceItem[] = [];
settings: Settings = { settings: Settings = {
language: getNavigatorLanguage() as Language, language: getUserLanguage(),
darkMode: !isSystemLightMode(), darkMode: !isSystemLightMode(),
autoUpdatesCheck: true autoUpdatesCheck: true
}; };

View File

@ -149,10 +149,13 @@ export const saveCache = async () => {
return SaveJson('cache.json', data); return SaveJson('cache.json', data);
}; };
export function getNavigatorLanguage() { export function getUserLanguage(): Language {
// const l = navigator.language.toLowerCase(); // const l = navigator.language.toLowerCase();
// if (['zh-hk', 'zh-mo', 'zh-tw', 'zh-cht', 'zh-hant'].includes(l)) return 'zhHant' // 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() { export function isSystemLightMode() {