diff --git a/electron-builder.yml b/electron-builder.yml
index 9a957254..779bd893 100644
--- a/electron-builder.yml
+++ b/electron-builder.yml
@@ -26,6 +26,7 @@ electronLanguages:
- zh-CN
- zh-TW
- en-US
+ - ru
# 完整运行时(emulator + platform-tools + 系统镜像),由 build/prepare-runtime.js 生成。
# 打进包里之后首次启动不再需要任何下载。
diff --git a/package-lock.json b/package-lock.json
index cd182c0a..9c2bb9b5 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,15 +1,16 @@
{
"name": "apkstart",
- "version": "0.3.0",
+ "version": "0.6.3",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "apkstart",
- "version": "0.3.0",
+ "version": "0.6.3",
"license": "MIT",
"os": [
- "win32"
+ "win32",
+ "linux"
],
"dependencies": {
"@napi-rs/lzma": "^1.5.3"
diff --git a/package.json b/package.json
index 91d61804..6463e65d 100644
--- a/package.json
+++ b/package.json
@@ -59,5 +59,9 @@
},
"dependencies": {
"@napi-rs/lzma": "^1.5.3"
+ },
+ "allowScripts": {
+ "electron@33.4.11": true,
+ "electron-winstaller@5.4.0": true
}
}
diff --git a/src/core/adb.js b/src/core/adb.js
index 08bb087d..32317869 100644
--- a/src/core/adb.js
+++ b/src/core/adb.js
@@ -1128,16 +1128,16 @@ class AdbClient {
}
/**
- * 保证系统语言是简体中文。
- * persist.sys.locale 是 SELinux 保护的只读属性,运行时改不了(会报
- * "Failed to set property"),真正生效靠 emulator 启动时的 -prop 注入。
- * 这里做的是能做的部分:把应用级 locale 和时区设好,让界面立刻中文、时间正确。
+ * 把 guest 的应用级 locale / 时区设成目标语言。系统 UI 语言由 emulator
+ * 启动参数 -change-locale 真正生效;这里补的是 settings 里的语言列表与时间格式。
+ * persist.sys.locale 是 SELinux 保护的只读属性,运行时改不了。
*/
- async ensureChineseLocale(locale = 'zh-CN') {
+ async ensureChineseLocale(locale = 'ru-RU') {
+ const tz = /^ru[-_]/i.test(String(locale)) ? 'Europe/Moscow' : 'Asia/Shanghai';
const cmds = [
'settings put system system_locales ' + locale,
- 'setprop persist.sys.timezone Asia/Shanghai',
- // 24 小时制 + 中文常见的日期格式
+ 'setprop persist.sys.timezone ' + tz,
+ // 24 小时制
'settings put system time_12_24 24',
];
await this.shell(cmds.join(' ; '), { timeout: 12000 }).catch(() => '');
diff --git a/src/core/emulator.js b/src/core/emulator.js
index 8135ada0..fb6e8616 100644
--- a/src/core/emulator.js
+++ b/src/core/emulator.js
@@ -623,11 +623,11 @@ class EmulatorEngine {
}
/**
- * 要注入的系统语言。默认简体中文;用户可在设置里改(engine.locale),
- * 设成 'en-US' 或 'off' 就回到镜像原生英文。
+ * 要注入的系统语言。默认俄语;用户可在设置里改(engine.locale),
+ * 设成 'en-US' / 'zh-CN' 或 'off' 就切回对应语言或镜像原生英文。
*/
_guestLocale() {
- const v = String(this.settings?.engine?.locale || 'zh-CN').trim();
+ const v = String(this.settings?.engine?.locale || 'ru-RU').trim();
if (!v || v === 'off' || /^false$/i.test(v)) return '';
return v;
}
@@ -672,7 +672,7 @@ class EmulatorEngine {
// 显式声明不限速:默认值虽然是 full,但某些 -gpu / -net 组合下会被带上
// 模拟器的保守配置,视频类应用(红果、抖音)首屏就会明显慢半拍。
args.push('-netdelay', 'none', '-netspeed', 'full');
- // 系统语言:默认简体中文。
+ // 系统语言:默认俄语(见 _guestLocale)。
// 实测 `-prop persist.sys.locale=zh-CN` 完全无效 —— 模拟器会拦截 persist.sys.*
// 这类受保护属性,ro.product.locale 又被镜像 build.prop 覆盖;guest 里 getprop
// 一个都看不到。官方专门给了 -change-locale:它会真正改系统语言并重启 framework,
diff --git a/src/core/engine.js b/src/core/engine.js
index 3708c06f..ca365cd1 100644
--- a/src/core/engine.js
+++ b/src/core/engine.js
@@ -52,6 +52,7 @@ class Runtime {
this.lastActivity = Date.now();
this._watchdog = null;
this._freeformReady = false;
+ this._localeReady = false;
this._client = null;
this._bootLog = [];
this._activeApps = new Set(); // 容器会话:当前打开的应用窗口
@@ -654,30 +655,31 @@ class Runtime {
if (!this._freeformReady) {
try { this._freeformReady = await client.ensureFreeform(); } catch (_) { /* ignore */ }
}
- // 中文环境(系统语言 + 中文输入法)每次**开机**只做一次。
- // 系统语言靠 emulator -prop 注入(SELinux 保护,运行时改不了),这里补的是
- // 应用级 locale / 时区,以及静默装好并启用随包带的谷歌拼音输入法。
- // 用户可在设置里关掉自动配置(engine.chineseIme=false)。
- if (!this._chineseReady && this.settings.engine.chineseIme !== false) {
+ const locale = this.settings.engine.locale || 'ru-RU';
+ // 系统语言和输入法是两件事:即便用户关掉中文输入法,Android 系统界面也必须
+ // 用选定的语言(默认俄语)。-change-locale 只在全量引导时执行,快照恢复会被
+ // 跳过,所以这里还要检查 system_locales 并在不对时作废快照、下次冷启动修正。
+ if (!this._localeReady) {
try {
- const locale = this.settings.engine.locale || 'zh-CN';
await client.ensureChineseLocale(locale);
+ await this._ensureSystemLocale(client, locale);
+ this._localeReady = true;
+ } catch (e) {
+ this.log(`系统语言初始化跳过:${e.message}`);
+ }
+ }
+ // 中文输入法单独处理;失败时允许下一次 prepare() 重试。
+ if (!this._chineseReady && this.settings.engine.chineseIme !== false) {
+ try {
const path = require('path');
const apk = path.join(this.appRoot, 'assets', 'PinyinIME.apk');
const r = await client.ensureChineseIme(apk, {
setDefault: this.settings.engine.chineseImeDefault !== false,
});
- // 只有真的成功了才置位。失败时允许下一次 prepare() 重试 ——
- // 否则一次偶发的 adb 抖动就会让这台机器永远没有中文输入法。
if (r && r.ok) this._chineseReady = true;
this.log(`中文输入法:${r.ok ? (r.installed ? '已安装并启用' : '已就绪') : (r.reason || '未就绪')}`);
- // -change-locale 只在「全量引导」时执行并重启 framework;从 quickboot 快照
- // 恢复时会被跳过。旧快照是英文的,所以检测到系统语言不对就作废快照、
- // 让下次开机冷启动一次(带 -change-locale)。之后存的新快照就是中文的,
- // 不用再重启。marker 保证一生只纠正一次。
- await this._ensureSystemLocale(client, locale);
} catch (e) {
- this.log(`中文环境初始化跳过:${e.message}`);
+ this.log(`中文输入法初始化跳过:${e.message}`);
}
}
this.startWatchdog();
@@ -687,9 +689,9 @@ class Runtime {
* 系统 UI 语言校正(一次性)。
*
* 实测结论(很容易踩错):-change-locale 生效后**不会**写 persist.sys.locale,
- * ro.product.locale 也仍是镜像的 en-US;它真正改的是
- * `settings system system_locales`(语言设置页显示「中文(中国)」,系统 UI 全中文)。
- * 所以判断「中文是否已经生效」要看 system_locales,不是 getprop。
+ * ro.product.locale 也仍是镜像的 en-US;它真正改的是 `settings system system_locales`
+ * (语言设置页显示目标语言,系统 UI 随之切换)。判断语言是否生效要看 system_locales,
+ * 不是 getprop。
*
* -change-locale 只在「全量引导」时执行并重启 framework;从 quickboot 快照恢复时
* 会被跳过。旧快照是英文的,所以检测到不对就作废快照、让下次开机冷启动一次。
@@ -698,12 +700,12 @@ class Runtime {
async _ensureSystemLocale(client, locale) {
const fs = require('fs');
const path = require('path');
- const want = String(locale || 'zh-CN');
+ const want = String(locale || 'ru-RU');
if (want === 'off' || want === 'en-US') return;
// 已经生效(system_locales 是目标语言,或语言列表里第一项是它)
const cur = await client.shell('settings get system system_locales', { timeout: 8000 }).catch(() => '');
const s = String(cur).trim();
- if (s === want || s.indexOf(want) === 0 || /^zh[-_]/.test(s)) return;
+ if (s === want || s.indexOf(want) === 0) return;
const marker = path.join(store.DATA_DIR, 'locale-' + want.replace(/[^a-zA-Z0-9_-]/g, '_') + '.done');
if (fs.existsSync(marker)) return;
try {
diff --git a/src/core/i18n.js b/src/core/i18n.js
new file mode 100644
index 00000000..c1c85d10
--- /dev/null
+++ b/src/core/i18n.js
@@ -0,0 +1,141 @@
+'use strict';
+/**
+ * 主进程本地化(i18n):托盘菜单、系统对话框、系统通知等「渲染层之外」的文案。
+ *
+ * - 语言来源:settings.language('auto' | 'zh' | 'ru')。
+ * 'auto' 时按系统语言判断:以 ru 开头 → 俄语,否则中文(保持原有行为)。
+ * - setDictionary() 由 src/main.js 在启动/改设置时注入字典文件(src/ui/i18n.js 的纯对象导出),
+ * 这样 core 目录不依赖 electron,字典也只维护一份。
+ * - 译文里可以用 {name} 占位符,tr() 会用第二个参数回填;找不到词条时原样返回中文串。
+ */
+let dict = null;
+let lang = 'zh';
+
+function normalizeLocale(loc) {
+ const s = String(loc || '').toLowerCase();
+ return s.startsWith('ru') ? 'ru' : 'zh';
+}
+
+/** 解析界面语言:优先 navigator.language,其次 Electron/系统 locale。 */
+function detectUiLanguage(electronApp) {
+ try {
+ const nav = electronApp && typeof electronApp.getPreferredSystemLanguages === 'function'
+ ? electronApp.getPreferredSystemLanguages() : null;
+ if (nav && nav.length) return normalizeLocale(nav[0]);
+ } catch (_) { /* ignore */ }
+ try {
+ if (electronApp && typeof electronApp.getLocale === 'function') {
+ return normalizeLocale(electronApp.getLocale());
+ }
+ } catch (_) { /* ignore */ }
+ return normalizeLocale(process.env.LANG || process.env.LC_ALL || '');
+}
+
+/** 由 settings.language + 系统语言算出当前应使用的界面语言。 */
+function resolveLanguage(setting, electronApp) {
+ if (setting === 'ru' || setting === 'zh') return setting;
+ return detectUiLanguage(electronApp);
+}
+
+function setLanguage(l) { lang = l === 'ru' ? 'ru' : 'zh'; }
+function getLanguage() { return lang; }
+function setDictionary(d) {
+ dict = d || null;
+ patternEntries = null;
+ patternCache.clear();
+ literalKeys = null;
+ fragmentCache.clear();
+}
+
+/* 主进程里大量文案是模板串:等它到达这里时 ${...} 已被替换成真实值,
+ 精确查表必落空。按词条骨架反查,命中后回填捕获到的值。 */
+let patternEntries = null;
+const patternCache = new Map();
+
+function escapeRe(s) {
+ return s.replace(/[.*+?^$()|[\]\\]/g, '\\$&').replace(/\{/g, '\\{').replace(/\}/g, '\\}');
+}
+
+function buildPatterns() {
+ if (patternEntries || !dict) return;
+ patternEntries = [];
+ for (const k of Object.keys(dict)) {
+ if (!/\{[^{}]+\}/.test(k)) continue;
+ // 纯占位符键会生成匹配任意串的万能模式,必须排除
+ if (!/[\u4e00-\u9fff]/.test(k.replace(/\{[^{}]+\}/g, ''))) continue;
+ const parts = [], names = [];
+ let last = 0, m;
+ const tok = /\{[^{}]+\}/g;
+ while ((m = tok.exec(k))) {
+ parts.push(escapeRe(k.slice(last, m.index)));
+ names.push(m[0]);
+ last = m.index + m[0].length;
+ }
+ parts.push(escapeRe(k.slice(last)));
+ let src = '';
+ for (let i = 0; i < names.length; i++) src += parts[i] + '([\\s\\S]*?)';
+ src += parts[names.length];
+ let re;
+ try { re = new RegExp('^' + src + '$'); } catch (_) { continue; }
+ patternEntries.push({ re, text: dict[k], names });
+ }
+}
+
+function fuzzyTranslate(raw) {
+ if (lang !== 'ru' || !dict || !raw || !/[\u4e00-\u9fff]/.test(raw)) return raw;
+ buildPatterns();
+ if (patternCache.has(raw)) return patternCache.get(raw);
+ let out = raw;
+ for (const p of patternEntries) {
+ const m = p.re.exec(raw);
+ if (!m) continue;
+ out = p.text.replace(/\{[^{}]+\}/g, (tok) => {
+ const idx = p.names.indexOf(tok);
+ return idx < 0 ? tok : m[idx + 1];
+ });
+ break;
+ }
+ patternCache.set(raw, out);
+ return out;
+}
+
+/* 整串查不到时,翻译其中夹着的独立中文词条(如「本机不匹配」)。 */
+let literalKeys = null;
+const fragmentCache = new Map();
+
+function fragmentTranslate(raw) {
+ if (fragmentCache.has(raw)) return fragmentCache.get(raw);
+ if (!literalKeys) {
+ literalKeys = Object.keys(dict)
+ .filter((k) => !/\{/.test(k) && /[\u4e00-\u9fff]/.test(k) && k.length >= 2)
+ .sort((a, b) => b.length - a.length);
+ }
+ let out = raw;
+ for (const k of literalKeys) {
+ const at = out.indexOf(k);
+ if (at < 0) continue;
+ const before = at > 0 ? out.charAt(at - 1) : '';
+ const after = at + k.length < out.length ? out.charAt(at + k.length) : '';
+ if (/[\u4e00-\u9fff]/.test(before) || /[\u4e00-\u9fff]/.test(after)) continue;
+ out = out.split(k).join(dict[k]);
+ }
+ fragmentCache.set(raw, out);
+ return out;
+}
+
+/** 翻译一条中文原文;无字典或非俄语环境时原样返回。 */
+function tr(zh, vars) {
+ let out = zh;
+ if (lang === 'ru' && dict) {
+ out = Object.prototype.hasOwnProperty.call(dict, zh) ? dict[zh] : fuzzyTranslate(zh);
+ if (out === zh) out = fragmentTranslate(zh);
+ }
+ if (vars) {
+ for (const k of Object.keys(vars)) {
+ out = out.split('{' + k + '}').join(String(vars[k]));
+ }
+ }
+ return out;
+}
+
+module.exports = { tr, setLanguage, getLanguage, setDictionary, resolveLanguage, normalizeLocale };
diff --git a/src/core/store.js b/src/core/store.js
index d46ee97a..a385d9a1 100644
--- a/src/core/store.js
+++ b/src/core/store.js
@@ -76,9 +76,11 @@ const DEFAULT_SETTINGS = {
// 网络加速:给模拟器指定国内公共 DNS。安卓默认的 10.0.2.3 要走主机 DNS,
// VPN / 公司网 / 某些运营商下解析会拖到几百毫秒,视频类应用首屏会明显发卡。
fastDns: true,
- // 系统语言:开机时由 emulator -prop 注入(guest 里 setprop 会被 SELinux 拒绝)。
- // 默认简体中文。设成 en-US 或 off 就回到镜像原生英文。
- locale: 'zh-CN',
+ // Android 系统语言:开机时由 emulator -change-locale 注入(guest 里 setprop 会被 SELinux 拒绝)。
+ // 默认俄语。设成 en-US / zh-CN 或 off 就切回对应的语言或镜像原生英文。
+ // localeChosen 只在用户于设置页主动选过语言后写入,用于避免升级时覆盖其选择。
+ locale: 'ru-RU',
+ localeChosen: false,
// 中文输入法:随包带 AOSP 谷歌拼音输入法,开机后静默安装并启用。
// 系统镜像只带 LatinIME(英文键盘),不装就打不了中文。
chineseIme: true,
@@ -312,6 +314,14 @@ const store = {
}
} catch (_) { /* 迁移失败不影响启动,保持读到的值 */ }
+ // 俄语版:老配置的默认语言是 zh-CN。只有用户没在设置页主动选过语言时才升级;
+ // 主动选过中文/英文/日文的人不会被改掉。回写在下次保存设置时自然落盘。
+ try {
+ const rawLocale = readJson(SETTINGS_FILE, {});
+ const chosen = !!(rawLocale.engine && rawLocale.engine.localeChosen);
+ if (!chosen && s.engine.locale === 'zh-CN') s.engine.locale = 'ru-RU';
+ } catch (_) { /* 迁移失败不影响启动 */ }
+
return s;
},
diff --git a/src/main.js b/src/main.js
index 7598aaae..3b0934bf 100644
--- a/src/main.js
+++ b/src/main.js
@@ -15,6 +15,14 @@ const { parseApk } = require('./core/apk');
const { drawAppIcon } = require('./core/png');
const orientation = require('./core/orientation');
+// 界面语言:跟随系统。主进程里 navigator.language 的等价物是
+// app.getPreferredSystemLanguages(),core/i18n 已按它判定。
+const i18n = require('./core/i18n');
+const uiI18n = require('./ui/i18n');
+i18n.setDictionary(uiI18n.DICT);
+i18n.setLanguage(i18n.resolveLanguage('auto', app));
+const tr = (zh, vars) => i18n.tr(zh, vars);
+
// 品牌 Logo(build/render-logo.js 生成);缺失时回退到程序化绘制的旧版图标
const LOGO_DIR = path.join(__dirname, 'ui', 'assets');
const LOGO_FILE = path.join(LOGO_DIR, 'logo.png');
@@ -559,7 +567,7 @@ async function attachAppWindow() {
const fallback = await appWin.embed().catch(() => false);
if (fallback) {
try {
- send('toast', { type: 'info', message: '模拟器原生窗口没能显示,本次临时用内置窗口接管画面' });
+ send('toast', { type: 'info', message: tr('模拟器原生窗口没能显示,本次临时用内置窗口接管画面') });
} catch (_) { /* 主窗口可能已关闭 */ }
}
return fallback;
@@ -819,9 +827,9 @@ async function enableWhpxFeatures() {
}
/** 商店版专用的手动引导文案:MSIX 包固定 mediumIL,提权通常拿不到 */
-const MSIX_ACCEL_HINT = '商店版无法自行提权。请手动开启一次:'
- + '按 Win+R → 输入 optionalfeatures → 勾选「Windows 虚拟机监控程序平台」'
- + '(HypervisorPlatform,WHPX 真正需要的那个),确定后重启电脑。';
+const MSIX_ACCEL_HINT = tr('商店版无法自行提权。请手动开启一次:')
+ + tr('按 Win+R → 输入 optionalfeatures → 勾选「Windows 虚拟机监控程序平台」')
+ + tr('(HypervisorPlatform,WHPX 真正需要的那个),确定后重启电脑。');
// ---------------- 主窗口 ----------------
@@ -942,7 +950,7 @@ function openManual(payload = {}) {
if (/^https?:\/\//i.test(url)) shell.openExternal(url);
});
}
- manualWindow.setTitle(`ApkStart 使用手册 · ${target.title}`);
+ manualWindow.setTitle(`ApkStart ${tr('使用手册')} · ${target.title}`);
manualWindow.loadFile(path.join(__dirname, 'ui', 'manual.html'), { hash: target.anchor });
manualWindow.once('ready-to-show', () => {
if (!manualWindow || manualWindow.isDestroyed()) return;
@@ -964,7 +972,9 @@ function notify(title, body) {
if (store.getSettings().notifyOnInstall === false) return;
try {
const { Notification } = require('electron');
- if (Notification.isSupported()) new Notification({ title, body, icon: nativeImage.createFromBuffer(ICON_PNG) }).show();
+ if (Notification.isSupported()) {
+ new Notification({ title: tr(title), body: tr(body), icon: nativeImage.createFromBuffer(ICON_PNG) }).show();
+ }
} catch (_) { /* ignore */ }
}
@@ -1019,8 +1029,8 @@ async function runAutodebug({ force = false } = {}) {
const fresh = added.filter((i) => i.severity === 'error');
if (fresh.length) {
const text = fresh.map((i) => i.title).join(';');
- send('toast', { type: 'error', message: `自动检测发现新问题:${text}(设置 → 诊断与修复)` });
- notify('自动检测发现新问题', `${text}。打开 ApkStart 的「设置 → 诊断与修复」可以一键处理。`);
+ send('toast', { type: 'error', message: tr('自动检测发现新问题:{text}(设置 → 诊断与修复)', { text }) });
+ notify('自动检测发现新问题', text + tr('。打开 ApkStart 的「设置 → 诊断与修复」可以一键处理。'));
appLog(`autodebug new issues: ${fresh.map((i) => i.code).join(',')}`);
}
}
@@ -1072,15 +1082,15 @@ function buildTray() {
? ((store.getApp(currentAppPkg) || {}).label || currentAppPkg)
: '';
const menu = Menu.buildFromTemplate([
- { label: '打开 ApkStart', click: () => showWindow() },
- { label: '使用手册', click: () => openManual({ topic: 'overview', reason: 'tray' }) },
+ { label: tr('打开 ApkStart'), click: () => showWindow() },
+ { label: tr('使用手册'), click: () => openManual({ topic: 'overview', reason: 'tray' }) },
{ type: 'separator' },
...(apps.length
? apps.map((a) => ({ label: a.label, click: () => runLaunch(a.package) }))
- : [{ label: '还没有安装应用', enabled: false }]),
+ : [{ label: tr('还没有安装应用'), enabled: false }]),
{ type: 'separator' },
{
- label: hasRunning ? `关闭当前应用(${runningLabel})` : '关闭当前应用',
+ label: hasRunning ? tr('关闭当前应用') + ' (' + runningLabel + ')' : tr('关闭当前应用'),
enabled: !!hasRunning,
click: () => {
const pkg = currentAppPkg;
@@ -1090,19 +1100,19 @@ function buildTray() {
},
},
{
- label: wantLandscapeFor(currentAppPkg) ? '切回竖屏(需重启运行时)' : '切换横屏(需重启运行时)',
+ label: wantLandscapeFor(currentAppPkg) ? tr('切回竖屏(需重启运行时)') : tr('切换横屏(需重启运行时)'),
enabled: !!currentAppPkg,
click: () => { rotateCurrentApp().catch(() => {}); },
},
{
- label: displaySettings().mode === 'fullscreen' ? '切回竖屏窗口' : '全屏(自适应屏幕)',
+ label: displaySettings().mode === 'fullscreen' ? tr('切回竖屏窗口') : tr('全屏(自适应屏幕)'),
click: () => { toggleDisplayMode(); },
},
- { label: '重建桌面/开始菜单快捷方式', click: () => { installer.ensureShortcuts().catch(() => {}); } },
- { label: '同步共享目录', click: () => sharer.sync() },
- { label: '设置', click: () => { showWindow(); send('ui:navigate', 'settings'); } },
+ { label: tr('重建桌面/开始菜单快捷方式'), click: () => { installer.ensureShortcuts().catch(() => {}); } },
+ { label: tr('同步共享目录'), click: () => sharer.sync() },
+ { label: tr('设置'), click: () => { showWindow(); send('ui:navigate', 'settings'); } },
{
- label: updateInfo && updateInfo.hasUpdate ? `发现新版本 ${updateInfo.tag}` : '检查更新',
+ label: updateInfo && updateInfo.hasUpdate ? tr('发现新版本') + ' ' + updateInfo.tag : tr('检查更新'),
click: async () => {
showWindow();
send('ui:navigate', 'settings');
@@ -1111,10 +1121,10 @@ function buildTray() {
if (info && info.hasUpdate && info.asset) {
const r = await dialog.showMessageBox(mainWindow || undefined, {
type: 'question',
- title: '发现新版本',
- message: `ApkStart ${info.tag} 已发布,当前版本 v${app.getVersion()}。现在更新吗?`,
+ title: tr('发现新版本'),
+ message: `ApkStart ${info.tag} ${tr('已发布,当前版本 v{ver}。现在更新吗?', { ver: app.getVersion() })}`,
detail: (info.notes || '').slice(0, 600),
- buttons: ['立即更新', '稍后'],
+ buttons: [tr('立即更新'), tr('稍后')],
defaultId: 0,
cancelId: 1,
});
@@ -1126,7 +1136,7 @@ function buildTray() {
},
{ type: 'separator' },
{
- label: '退出',
+ label: tr('退出'),
click: async () => {
try { appWin.close({ keepApp: true }); } catch (_) { /* ignore */ }
quitting = true;
@@ -1136,7 +1146,7 @@ function buildTray() {
]);
tray.setContextMenu(menu);
};
- tray.setToolTip('ApkStart — 安卓应用运行器');
+ tray.setToolTip(tr('ApkStart — 安卓应用运行器'));
// Windows 托盘的惯例是单击就打开主窗口(双击当然也可以)。
// 之前只绑了 double-click,用户单击没反应,会以为托盘图标坏了。
// 右键才出菜单,所以这里单击直接 showWindow 不会和菜单冲突。
@@ -1156,10 +1166,10 @@ async function runInstall(filePath) {
// 同一个包正在装(用户连点了几次图标 / 拖了好几次)→ 只提示一次,别重复跑一遍安装
if (installBusy) {
if (installBusy === filePath) {
- send('toast', { type: 'info', message: '这个 APK 正在安装中,请稍等…' });
+ send('toast', { type: 'info', message: tr('这个 APK 正在安装中,请稍等…') });
return { ok: false, error: '正在安装中' };
}
- send('toast', { type: 'info', message: '已有安装任务在进行,请等它装完。' });
+ send('toast', { type: 'info', message: tr('已有安装任务在进行,请等它装完。') });
return { ok: false, error: '已有安装任务在进行' };
}
installBusy = filePath;
@@ -1169,7 +1179,7 @@ async function runInstall(filePath) {
send('install:done', result);
// 新建的桌面图标要让资源管理器立刻刷新,否则用户会以为「没创建快捷方式」
windowctl.refreshShell().catch(() => {});
- notify('安装完成', `${result.app.label} 已安装${result.app.shortcutPath ? ',桌面快捷方式已创建' : ''}`);
+ notify('安装完成', `${result.app.label} ${tr('已安装')}${result.app.shortcutPath ? tr(',桌面快捷方式已创建') : ''}`);
return result;
} catch (e) {
send('install:error', { message: e.message, file: filePath });
@@ -1489,7 +1499,7 @@ async function launchOne(pkg) {
// 下次点应用还是走同一条隐藏 → embed 的路径。
if (winAgent) armAgent(winAgent).catch(() => {});
showWindow();
- send('toast', { type: 'error', message: `启动失败:${e.message}` });
+ send('toast', { type: 'error', message: tr('启动失败:{msg}', { msg: e.message }) });
return { ok: false, error: e.message };
}
}
@@ -1602,7 +1612,7 @@ function registerIpc() {
// 选文件夹(用于把运行时/镜像/已装应用挪到非系统盘)
ipcMain.handle('dialog:openDir', async (_e, defaultPath) => {
const r = await dialog.showOpenDialog(mainWindow, {
- title: '选择数据存放目录',
+ title: tr('选择数据存放目录'),
defaultPath: defaultPath || store.DATA_DIR,
properties: ['openDirectory', 'createDirectory'],
});
@@ -1632,8 +1642,8 @@ function registerIpc() {
ipcMain.handle('apk:pick', async () => {
const r = await dialog.showOpenDialog(mainWindow, {
- title: '选择要安装的 APK',
- filters: [{ name: 'Android 应用', extensions: ['apk', 'apks', 'xapk'] }],
+ title: tr('选择要安装的 APK'),
+ filters: [{ name: tr('Android 应用'), extensions: ['apk', 'apks', 'xapk'] }],
properties: ['openFile', 'multiSelections'],
});
if (r.canceled) return [];
@@ -1943,8 +1953,8 @@ function registerIpc() {
ipcMain.handle('drivers:import', async () => {
const drv = require('./core/drivers');
const r = await dialog.showOpenDialog(mainWindow, {
- title: '选择驱动文件(.json)',
- filters: [{ name: '驱动 JSON', extensions: ['json'] }],
+ title: tr('选择驱动文件(.json)'),
+ filters: [{ name: tr('驱动 JSON'), extensions: ['json'] }],
properties: ['openFile'],
});
if (r.canceled || !r.filePaths.length) return { ok: false, canceled: true };
@@ -1963,9 +1973,9 @@ function registerIpc() {
const overview = await driverOverview();
const tpl = drv.templateFromHost(overview.host);
const r = await dialog.showSaveDialog(mainWindow, {
- title: '导出本机驱动模板',
+ title: tr('导出本机驱动模板'),
defaultPath: path.join(drv.userDir(store), `${tpl.id}.json`),
- filters: [{ name: '驱动 JSON', extensions: ['json'] }],
+ filters: [{ name: tr('驱动 JSON'), extensions: ['json'] }],
});
if (r.canceled || !r.filePath) return { ok: false, canceled: true };
fs.mkdirSync(path.dirname(r.filePath), { recursive: true });
@@ -2192,10 +2202,10 @@ function registerIpc() {
ipcMain.handle('app:confirm', async (_e, opts = {}) => {
const { response } = await dialog.showMessageBox(mainWindow || undefined, {
type: opts.type || 'question',
- title: opts.title || '确认',
- message: opts.message || '',
- detail: opts.detail || '',
- buttons: ['取消', opts.okLabel || '确定'],
+ title: opts.title || tr('确认'),
+ message: tr(opts.message || ''),
+ detail: tr(opts.detail || ''),
+ buttons: [tr('取消'), tr(opts.okLabel || '确定')],
defaultId: 1,
cancelId: 0,
noLink: true,
@@ -2269,7 +2279,7 @@ function registerIpc() {
try {
const r = runtime.emulator.resizeDataPartition(mb);
appLog(`data partition -> ${want}GB: ${JSON.stringify(r)}`);
- if (r && r.ok) notify('数据分区已调整', `安卓可用空间约 ${want} GB${stopped ? '(运行时已重启)' : ''}`);
+ if (r && r.ok) notify('数据分区已调整', tr('安卓可用空间约 {gb} GB{note}', { gb: want, note: stopped ? tr('(运行时已重启)') : '' }));
return { ok: !!(r && r.ok), stopped, ...r, ...runtime.emulator.dataInfo() };
} catch (e) {
return { ok: false, error: e.message };
@@ -2283,15 +2293,15 @@ function registerIpc() {
const preview = await runtime.cleanup(pass);
const { response } = await dialog.showMessageBox(mainWindow, {
type: 'warning',
- buttons: ['取消', `清理 ${preview.candidates.length} 项`],
+ buttons: [tr('取消'), tr('清理 {n} 项', { n: preview.candidates.length })],
defaultId: 0,
cancelId: 0,
- title: '确认清理运行时缓存',
- message: `将释放约 ${(preview.candidates.reduce((n, c) => n + c.size, 0) / 1048576).toFixed(0)} MB`,
- detail: (opts.includeSnapshots
+ title: tr('确认清理运行时缓存'),
+ message: tr('将释放约 {mb} MB', { mb: (preview.candidates.reduce((n, c) => n + c.size, 0) / 1048576).toFixed(0) }),
+ detail: tr(opts.includeSnapshots
? '会先停止运行时,再删除旧镜像、当前 AVD 的快速启动快照、锁文件和非活动 AVD 的缓存。已安装的应用本身保留(只清快照),'
: '只删除旧镜像、旧快照、锁文件和非活动 AVD 的缓存,已安装的应用会保留。')
- + '此操作不可撤销,建议先导出诊断报告。',
+ + tr('此操作不可撤销,建议先导出诊断报告。'),
});
if (response !== 1) return { ...preview, cancelled: true };
return runtime.cleanup({ apply: true, aggressive: !!opts.aggressive, includeSnapshots: !!opts.includeSnapshots });
@@ -2556,8 +2566,8 @@ function registerIpc() {
ipcMain.handle('provision:importIso', async () => {
const r = await dialog.showOpenDialog(mainWindow, {
- title: '选择 Android-x86 / Bliss OS 系统镜像',
- filters: [{ name: '系统镜像', extensions: ['iso', 'img'] }],
+ title: tr('选择 Android-x86 / Bliss OS 系统镜像'),
+ filters: [{ name: tr('系统镜像'), extensions: ['iso', 'img'] }],
properties: ['openFile'],
});
if (r.canceled) return { ok: false, canceled: true };
@@ -2570,8 +2580,8 @@ function registerIpc() {
ipcMain.handle('provision:importDisk', async () => {
const r = await dialog.showOpenDialog(mainWindow, {
- title: '选择已安装 Android 的虚拟磁盘',
- filters: [{ name: '虚拟磁盘', extensions: ['qcow2', 'img', 'vmdk', 'raw'] }],
+ title: tr('选择已安装 Android 的虚拟磁盘'),
+ filters: [{ name: tr('虚拟磁盘'), extensions: ['qcow2', 'img', 'vmdk', 'raw'] }],
properties: ['openFile'],
});
if (r.canceled) return { ok: false, canceled: true };
@@ -3148,8 +3158,8 @@ if (!gotLock) {
if (freeMB && freeMB < 3072) {
appLog(`LOW_DISK free=${freeMB}MB dir=${store.DATA_DIR}`);
setTimeout(() => {
- notify('磁盘空间不足', `只剩 ${(freeMB / 1024).toFixed(1)} GB。请到「设置 → 系统集成」把安卓数据目录/运行时目录改到其他盘,或先清理磁盘。`);
- send('toast', { type: 'error', message: `磁盘只剩 ${(freeMB / 1024).toFixed(1)} GB,安卓可能无法启动(设置 → 系统集成 可换盘)` });
+ notify('磁盘空间不足', tr('只剩 {gb} GB。请到「设置 → 系统集成」把安卓数据目录/运行时目录改到其他盘,或先清理磁盘。', { gb: (freeMB / 1024).toFixed(1) }));
+ send('toast', { type: 'error', message: tr('磁盘只剩 {gb} GB,安卓可能无法启动(设置 → 系统集成 可换盘)', { gb: (freeMB / 1024).toFixed(1) }) });
}, 3000).unref?.();
}
}
@@ -3222,7 +3232,7 @@ if (!gotLock) {
// 再并发下载解压只会让桌面更卡。真有应用要打开时 ensure() 自会准备。
setTimeout(() => {
autoDeploy().then((r) => {
- if (r && r.ok) send('toast', { type: 'ok', message: '运行时已自动准备完成' });
+ if (r && r.ok) send('toast', { type: 'ok', message: tr('运行时已自动准备完成') });
}).catch(() => {});
}, 20000).unref?.();
diff --git a/src/ui/app.js b/src/ui/app.js
index d734a2cf..6c97a5f9 100644
--- a/src/ui/app.js
+++ b/src/ui/app.js
@@ -2,6 +2,7 @@
const api = window.apkstart;
const $ = (id) => document.getElementById(id);
+const tr = window.ApkStartI18n && window.ApkStartI18n.tr ? window.ApkStartI18n.tr.bind(window.ApkStartI18n) : (zh) => zh;
const state = {
apps: [],
@@ -1089,7 +1090,7 @@ function fillSettings(s) {
if ($('setRenderSize')) $('setRenderSize').value = eng.renderSize || 'auto';
if ($('setDataGB')) $('setDataGB').value = String(Number(eng.dataPartitionGB || 0));
if ($('setFastDns')) $('setFastDns').checked = eng.fastDns !== false;
- if ($('setLocale')) $('setLocale').value = eng.locale || 'zh-CN';
+ if ($('setLocale')) $('setLocale').value = eng.locale || 'ru-RU';
if ($('setChineseIme')) $('setChineseIme').checked = eng.chineseIme !== false;
if ($('setKeepSnapshot')) $('setKeepSnapshot').checked = eng.keepSnapshot !== false;
$('setDisplayMode').value = d.mode === 'fullscreen' ? 'fullscreen' : 'window';
@@ -1684,7 +1685,7 @@ function bindSettings() {
}
if ($('setLocale')) {
$('setLocale').addEventListener('change', async (e) => {
- state.settings = await api.setSettings({ engine: { locale: e.target.value } });
+ state.settings = await api.setSettings({ engine: { locale: e.target.value, localeChosen: true } });
toast({ title: '系统语言已更新', body: '下次重启安卓运行时后生效', type: 'ok' });
});
}
@@ -1713,7 +1714,7 @@ function bindSettings() {
if (!gb) { toast({ title: '先选一个容量', body: '「自动」表示由软件按磁盘余量决定,不需要扩容', type: 'info' }); return; }
const { response } = await api.confirm({
title: '立刻把安卓数据分区扩容?',
- message: `将把 /data 调整为 ${gb} GB(就地扩容,已装应用和存档都会保留)。`,
+ message: tr(`将把 /data 调整为 ${gb} GB(就地扩容,已装应用和存档都会保留)。`, { gb }),
detail: '扩容需要先关掉正在运行的安卓应用,完成后下次打开应用会重新引导,约多花十几秒。',
okLabel: '开始扩容',
});
@@ -1729,7 +1730,7 @@ function bindSettings() {
// 这是明确的数据丢失操作,必须单独再确认一次。
const again = await api.confirm({
title: '需要重置安卓数据才能扩容',
- message: `安卓正在使用快速启动差量盘,就地扩容改不到它。要拿到 ${gb} GB 空间,必须按新容量重建 /data。`,
+ message: tr(`安卓正在使用快速启动差量盘,就地扩容改不到它。要拿到 ${gb} GB 空间,必须按新容量重建 /data。`, { gb }),
detail: '重建会清空已安装的应用与存档(模拟器本身和镜像不受影响)。确定继续吗?',
okLabel: '清空并重建',
});
@@ -2064,7 +2065,7 @@ function bindSettings() {
const ok = await api.confirm({
type: 'warning',
title: '清理旧版本残留?',
- message: `找到 ${items.length} 项残留,约 ${mb} MB:`,
+ message: tr(`找到 ${items.length} 项残留,约 ${mb} MB:`, { n: items.length, mb }),
detail: `${lines.join('\n')}\n\n只删除「旧版本程序目录 / 已失效的卸载项 / 更新临时文件」,`
+ '当前正在运行的版本和你的应用数据都不会动。',
buttons: ['取消', '开始清理'],
diff --git a/src/ui/i18n.js b/src/ui/i18n.js
new file mode 100644
index 00000000..7f3b22ed
--- /dev/null
+++ b/src/ui/i18n.js
@@ -0,0 +1,2378 @@
+'use strict';
+/**
+ * 运行时翻译字典(由 tools/i18n/build.js 从 translations.ru.json 生成,请勿手改)。
+ *
+ * 同一个文件两处复用:
+ * - 渲染层(index / shell / splash):