mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 05:00:30 +08:00
feat: Auto-detect OS language and set app language accordingly
This commit is contained in:
parent
c60b041192
commit
b102c4c59b
@ -2,7 +2,7 @@ import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
|||||||
import { registerIpcMainHandlers } from './utils/ipc'
|
import { registerIpcMainHandlers } from './utils/ipc'
|
||||||
import windowStateKeeper from 'electron-window-state'
|
import windowStateKeeper from 'electron-window-state'
|
||||||
import { app, shell, BrowserWindow, Menu, dialog, Notification, powerMonitor } from 'electron'
|
import { app, shell, BrowserWindow, Menu, dialog, Notification, powerMonitor } from 'electron'
|
||||||
import { addProfileItem, getAppConfig } from './config'
|
import { addProfileItem, getAppConfig, patchAppConfig } from './config'
|
||||||
import { quitWithoutCore, startCore, stopCore } from './core/manager'
|
import { quitWithoutCore, startCore, stopCore } from './core/manager'
|
||||||
import { triggerSysProxy } from './sys/sysproxy'
|
import { triggerSysProxy } from './sys/sysproxy'
|
||||||
import icon from '../../resources/icon.png?asset'
|
import icon from '../../resources/icon.png?asset'
|
||||||
@ -117,6 +117,12 @@ powerMonitor.on('shutdown', async () => {
|
|||||||
app.exit()
|
app.exit()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 获取系统语言
|
||||||
|
function getSystemLanguage(): 'zh-CN' | 'en-US' {
|
||||||
|
const locale = app.getLocale()
|
||||||
|
return locale.startsWith('zh') ? 'zh-CN' : 'en-US'
|
||||||
|
}
|
||||||
|
|
||||||
// This method will be called when Electron has finished
|
// This method will be called when Electron has finished
|
||||||
// initialization and is ready to create browser windows.
|
// initialization and is ready to create browser windows.
|
||||||
// Some APIs can only be used after this event occurs.
|
// Some APIs can only be used after this event occurs.
|
||||||
@ -126,6 +132,12 @@ app.whenReady().then(async () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const appConfig = await getAppConfig()
|
const appConfig = await getAppConfig()
|
||||||
|
// 如果配置中没有语言设置,则使用系统语言
|
||||||
|
if (!appConfig.language) {
|
||||||
|
const systemLanguage = getSystemLanguage()
|
||||||
|
await patchAppConfig({ language: systemLanguage })
|
||||||
|
appConfig.language = systemLanguage
|
||||||
|
}
|
||||||
await initI18n({ lng: appConfig.language })
|
await initI18n({ lng: appConfig.language })
|
||||||
await initPromise
|
await initPromise
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user