修复识别系统默认语言

This commit is contained in:
whyour
2026-07-04 01:13:59 +08:00
parent 38d84f9f31
commit 1953022b99
5 changed files with 25 additions and 53 deletions
+7 -2
View File
@@ -1,3 +1,5 @@
import { shareStore } from './store';
const messages: Record<string, Record<string, string>> = {
zh: {},
en: {
@@ -148,10 +150,13 @@ let currentLang: string = 'zh';
export function setLang(lang: string) {
currentLang = lang || 'zh';
shareStore.setLang(currentLang);
}
export function getLang(): string {
return currentLang;
/** 系统默认语言:Intl 检测 → 'zh'(仅返回 zh/en */
export function systemLang(): string {
const prefix = Intl.DateTimeFormat().resolvedOptions().locale.split('-')[0];
return prefix === 'en' ? 'en' : 'zh';
}
export function t(key: string, lang?: string): string {
+8
View File
@@ -8,11 +8,13 @@ import path from 'path';
export enum EKeyv {
'apps' = 'apps',
'authInfo' = 'authInfo',
'lang' = 'lang',
}
export interface IKeyvStore {
apps: App[];
authInfo: AuthInfo;
lang: string;
}
const keyvSqlite = new KeyvSqlite(path.join(config.dbPath, 'keyv.sqlite'));
@@ -31,4 +33,10 @@ export const shareStore = {
updateApps(apps: App[]) {
return keyvStore.set<IKeyvStore['apps']>(EKeyv.apps, apps);
},
getLang() {
return keyvStore.get<IKeyvStore['lang']>(EKeyv.lang);
},
setLang(value: IKeyvStore['lang']) {
return keyvStore.set<IKeyvStore['lang']>(EKeyv.lang, value);
},
};