feat: 合并代码

This commit is contained in:
duanshuwen
2025-12-21 20:25:38 +08:00
parent 11702dc9d2
commit 7d6b07e092
56 changed files with 2533 additions and 379 deletions

36
src/main/utils/index.ts Normal file
View File

@@ -0,0 +1,36 @@
import { CONFIG_KEYS } from '@common/constants'
import logManager from '@main/service/logger'
import configManager from '@main/service/config-service'
import path from 'node:path'
import en from '@locales/en.json'
import zh from '@locales/zh.json'
type MessageSchema = typeof zh;
const messages: Record<string, MessageSchema> = { en, zh }
export function createTranslator() {
return (key?: string) => {
if (!key) return void 0;
try {
const keys = key?.split('.');
let result: any = messages[configManager.get(CONFIG_KEYS.LANGUAGE)];
for (const _key of keys) {
result = result[_key];
}
return result as string;
} catch (e) {
logManager.error('failed to translate key:', key, e);
return key
}
}
}
let logo: string | void = void 0;
export function createLogo() {
if (logo != null) {
return logo;
}
logo = path.join(__dirname, 'logo.ico');
return logo;
}