Skip to content
This repository has been archived by the owner on Feb 5, 2025. It is now read-only.

Commit

Permalink
feat: add missing i18n translations
Browse files Browse the repository at this point in the history
  • Loading branch information
pompurin404 committed Feb 4, 2025
1 parent 4a48445 commit fcf5710
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 50 deletions.
11 changes: 6 additions & 5 deletions src/main/core/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ import os from 'os'
import { createWriteStream, existsSync } from 'fs'
import { uploadRuntimeConfig } from '../resolve/gistApi'
import { startMonitor } from '../resolve/trafficMonitor'
import i18next from '../../shared/i18n'

chokidar.watch(path.join(mihomoCoreDir(), 'meta-update'), {}).on('unlinkDir', async () => {
try {
await stopCore(true)
await startCore()
} catch (e) {
dialog.showErrorBox('内核启动出错', `${e}`)
dialog.showErrorBox(i18next.t('mihomo.error.coreStartFailed'), `${e}`)
}
})

Expand Down Expand Up @@ -130,7 +131,7 @@ export async function startCore(detached = false): Promise<Promise<void>[]> {
patchControledMihomoConfig({ tun: { enable: false } })
mainWindow?.webContents.send('controledMihomoConfigUpdated')
ipcMain.emit('updateTrayMenu')
reject('虚拟网卡启动失败, 请尝试手动授予内核权限')
reject(i18next.t('tun.error.tunPermissionDenied'))
}

if (
Expand Down Expand Up @@ -189,7 +190,7 @@ export async function restartCore(): Promise<void> {
try {
await startCore()
} catch (e) {
dialog.showErrorBox('内核启动出错', `${e}`)
dialog.showErrorBox(i18next.t('mihomo.error.coreStartFailed'), `${e}`)
}
}

Expand All @@ -200,7 +201,7 @@ export async function keepCoreAlive(): Promise<void> {
await writeFile(path.join(dataDir(), 'core.pid'), child.pid.toString())
}
} catch (e) {
dialog.showErrorBox('内核启动出错', `${e}`)
dialog.showErrorBox(i18next.t('mihomo.error.coreStartFailed'), `${e}`)
}
}

Expand Down Expand Up @@ -230,7 +231,7 @@ async function checkProfile(): Promise<void> {
.split('\n')
.filter((line) => line.includes('level=error'))
.map((line) => line.split('level=error')[1])
throw new Error(`Profile Check Failed:\n${errorLines.join('\n')}`)
throw new Error(`${i18next.t('mihomo.error.profileCheckFailed')}:\n${errorLines.join('\n')}`)
} else {
throw error
}
Expand Down
15 changes: 8 additions & 7 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ if (process.platform === 'win32' && !is.dev && !process.argv.includes('noadmin')
// ignore
}
dialog.showErrorBox(
i18next.t('main.error.adminRequired'),
`${i18next.t('main.error.adminRequired')}\n${createErrorStr}\n${eStr}`
i18next.t('common.error.adminRequired'),
`${i18next.t('common.error.adminRequired')}\n${createErrorStr}\n${eStr}`
)
} finally {
app.exit()
Expand Down Expand Up @@ -123,12 +123,13 @@ powerMonitor.on('shutdown', async () => {
app.whenReady().then(async () => {
// Set app user model id for windows
electronApp.setAppUserModelId('party.mihomo.app')

try {
const appConfig = await getAppConfig()
await initI18n({ lng: appConfig.language })
await initPromise
} catch (e) {
dialog.showErrorBox(i18next.t('main.error.initFailed'), `${e}`)
dialog.showErrorBox(i18next.t('common.error.initFailed'), `${e}`)
app.quit()
}
try {
Expand All @@ -137,7 +138,7 @@ app.whenReady().then(async () => {
await initProfileUpdater()
})
} catch (e) {
dialog.showErrorBox(i18next.t('main.error.coreStartFailed'), `${e}`)
dialog.showErrorBox(i18next.t('mihomo.error.coreStartFailed'), `${e}`)
}
try {
await startMonitor()
Expand Down Expand Up @@ -178,18 +179,18 @@ async function handleDeepLink(url: string): Promise<void> {
const profileUrl = urlObj.searchParams.get('url')
const profileName = urlObj.searchParams.get('name')
if (!profileUrl) {
throw new Error(i18next.t('main.error.urlParamMissing'))
throw new Error(i18next.t('profiles.error.urlParamMissing'))
}
await addProfileItem({
type: 'remote',
name: profileName ?? undefined,
url: profileUrl
})
mainWindow?.webContents.send('profileConfigUpdated')
new Notification({ title: i18next.t('main.notification.importSuccess') }).show()
new Notification({ title: i18next.t('profiles.notification.importSuccess') }).show()
break
} catch (e) {
dialog.showErrorBox(i18next.t('main.error.importFailed'), `${url}\n${e}`)
dialog.showErrorBox(i18next.t('profiles.error.importFailed'), `${url}\n${e}`)
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/main/resolve/shortcut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { triggerSysProxy } from '../sys/sysproxy'
import { patchMihomoConfig } from '../core/mihomoApi'
import { quitWithoutCore, restartCore } from '../core/manager'
import { floatingWindow, triggerFloatingWindow } from './floatingWindow'
import i18next from '../../shared/i18n'

export async function registerShortcut(
oldShortcut: string,
Expand Down Expand Up @@ -42,7 +43,7 @@ export async function registerShortcut(
await triggerSysProxy(!enable)
await patchAppConfig({ sysProxy: { enable: !enable } })
new Notification({
title: `系统代理已${!enable ? '开启' : '关闭'}`
title: i18next.t(!enable ? 'common.notification.systemProxyEnabled' : 'common.notification.systemProxyDisabled')
}).show()
mainWindow?.webContents.send('appConfigUpdated')
floatingWindow?.webContents.send('appConfigUpdated')
Expand All @@ -65,7 +66,7 @@ export async function registerShortcut(
}
await restartCore()
new Notification({
title: `虚拟网卡已${!enable ? '开启' : '关闭'}`
title: i18next.t(!enable ? 'common.notification.tunEnabled' : 'common.notification.tunDisabled')
}).show()
mainWindow?.webContents.send('controledMihomoConfigUpdated')
floatingWindow?.webContents.send('appConfigUpdated')
Expand All @@ -81,7 +82,7 @@ export async function registerShortcut(
await patchControledMihomoConfig({ mode: 'rule' })
await patchMihomoConfig({ mode: 'rule' })
new Notification({
title: '已切换至规则模式'
title: i18next.t('common.notification.ruleMode')
}).show()
mainWindow?.webContents.send('controledMihomoConfigUpdated')
ipcMain.emit('updateTrayMenu')
Expand All @@ -92,7 +93,7 @@ export async function registerShortcut(
await patchControledMihomoConfig({ mode: 'global' })
await patchMihomoConfig({ mode: 'global' })
new Notification({
title: '已切换至全局模式'
title: i18next.t('common.notification.globalMode')
}).show()
mainWindow?.webContents.send('controledMihomoConfigUpdated')
ipcMain.emit('updateTrayMenu')
Expand All @@ -103,7 +104,7 @@ export async function registerShortcut(
await patchControledMihomoConfig({ mode: 'direct' })
await patchMihomoConfig({ mode: 'direct' })
new Notification({
title: '已切换至直连模式'
title: i18next.t('common.notification.directMode')
}).show()
mainWindow?.webContents.send('controledMihomoConfigUpdated')
ipcMain.emit('updateTrayMenu')
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/components/settings/webdav-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const WebdavConfig: React.FC = () => {
className="ml-1"
onPress={handleRestore}
>
{t('webdav.restore')}
{t('webdav.restore.title')}
</Button>
</div>
</SettingCard>
Expand Down
32 changes: 17 additions & 15 deletions src/renderer/src/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
"restoreFailed": "Failed to restore: {{error}}",
"deleteFailed": "Failed to delete: {{error}}",
"shortcutRegistrationFailed": "Failed to register shortcut",
"shortcutRegistrationFailedWithError": "Failed to register shortcut: {{error}}"
"shortcutRegistrationFailedWithError": "Failed to register shortcut: {{error}}",
"adminRequired": "Please run with administrator privileges for first launch",
"initFailed": "Application initialization failed"
},
"updater": {
"versionReady": "v{{version}} Version Ready",
Expand Down Expand Up @@ -152,7 +154,10 @@
"logLevel": "Log Level",
"selectLogLevel": "Select Log Level",
"silent": "Silent",
"error": "Error",
"error": {
"coreStartFailed": "Core start failed",
"profileCheckFailed": "Profile Check Failed"
},
"warning": "Warning",
"info": "Info",
"debug": "Debug",
Expand Down Expand Up @@ -310,6 +315,7 @@
}
},
"proxies": {
"title": "Proxy Groups & Nodes",
"card": {
"title": "ProxyGrp"
},
Expand Down Expand Up @@ -418,6 +424,9 @@
"notifications": {
"coreAuthSuccess": "Core Authorization Successful",
"firewallResetSuccess": "Firewall Reset Successful"
},
"error": {
"tunPermissionDenied": "TUN interface start failed, please try to manually grant core permissions"
}
},
"dns": {
Expand Down Expand Up @@ -471,7 +480,9 @@
"visit": "Visit Sub-Store"
},
"error": {
"unsupportedFileType": "Unsupported file type"
"unsupportedFileType": "Unsupported file type",
"urlParamMissing": "Missing parameter: url",
"importFailed": "Subscription import failed"
},
"emptyProfile": "Empty Profile",
"viewRuntimeConfig": "View Current Runtime Config",
Expand Down Expand Up @@ -506,6 +517,9 @@
"expired": "Expired",
"remainingDays": "{{days}} days",
"lastUpdate": "Last updated: {{time}}"
},
"notification": {
"importSuccess": "Subscription imported successfully"
}
},
"outbound": {
Expand Down Expand Up @@ -708,17 +722,5 @@
"title": "Tutorial Complete",
"description": "Now that you understand the basic usage of the software, import your subscription and start using it. Enjoy!\nYou can also join our official <a href=\"https://t.me/mihomo_party_group\" target=\"_blank\">Telegram group</a> for the latest news."
}
},
"main": {
"error": {
"adminRequired": "Please run with administrator privileges for first launch",
"initFailed": "Application initialization failed",
"coreStartFailed": "Core startup error",
"importFailed": "Subscription import failed",
"urlParamMissing": "Missing parameter: url"
},
"notification": {
"importSuccess": "Subscription imported successfully"
}
}
}
34 changes: 18 additions & 16 deletions src/renderer/src/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
"restoreFailed": "恢复失败:{{error}}",
"deleteFailed": "删除失败:{{error}}",
"shortcutRegistrationFailed": "快捷键注册失败",
"shortcutRegistrationFailedWithError": "快捷键注册失败:{{error}}"
"shortcutRegistrationFailedWithError": "快捷键注册失败:{{error}}",
"adminRequired": "首次启动请以管理员权限运行",
"initFailed": "应用初始化失败"
},
"updater": {
"versionReady": "v{{version}} 版本就绪",
Expand Down Expand Up @@ -152,7 +154,10 @@
"logLevel": "日志等级",
"selectLogLevel": "选择日志等级",
"silent": "静默",
"error": "错误",
"error": {
"coreStartFailed": "内核启动出错",
"profileCheckFailed": "配置检查失败"
},
"warning": "警告",
"info": "信息",
"debug": "调试",
Expand Down Expand Up @@ -310,6 +315,7 @@
}
},
"proxies": {
"title": "代理组与节点",
"card": {
"title": "代理组"
},
Expand Down Expand Up @@ -418,6 +424,9 @@
"notifications": {
"coreAuthSuccess": "内核授权成功",
"firewallResetSuccess": "防火墙重设成功"
},
"error": {
"tunPermissionDenied": "虚拟网卡启动失败,请尝试手动授予内核权限"
}
},
"dns": {
Expand Down Expand Up @@ -471,7 +480,9 @@
"visit": "访问 Sub-Store"
},
"error": {
"unsupportedFileType": "不支持的文件类型"
"unsupportedFileType": "不支持的文件类型",
"urlParamMissing": "缺少参数 url",
"importFailed": "订阅导入失败"
},
"emptyProfile": "空白订阅",
"viewRuntimeConfig": "查看当前运行时配置",
Expand Down Expand Up @@ -506,7 +517,10 @@
"feature": "功能"
},
"openFile": "打开文件",
"home": "主页"
"home": "主页",
"notification": {
"importSuccess": "订阅导入成功"
}
},
"outbound": {
"title": "出站模式",
Expand Down Expand Up @@ -708,17 +722,5 @@
"title": "教程结束",
"description": "现在您已经了解了软件的基本用法,导入您的订阅开始使用吧,祝您使用愉快!\n您还可以加入我们的官方 <a href=\"https://t.me/mihomo_party_group\" target=\"_blank\">Telegram 群组</a> 获取最新资讯"
}
},
"main": {
"error": {
"adminRequired": "首次启动请以管理员权限运行",
"initFailed": "应用初始化失败",
"coreStartFailed": "内核启动出错",
"importFailed": "订阅导入失败",
"urlParamMissing": "缺少参数 url"
},
"notification": {
"importSuccess": "订阅导入成功"
}
}
}
2 changes: 1 addition & 1 deletion src/renderer/src/pages/proxies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ const Proxies: React.FC = () => {

return (
<BasePage
title={t('proxies.card.title')}
title={t('proxies.title')}
header={
<>
<Button
Expand Down

0 comments on commit fcf5710

Please sign in to comment.