@seekskyworld/open-browser 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/CONTRIBUTING.md +2 -0
  2. package/Docs/desktop-packages.md +45 -0
  3. package/Docs//350/267/250/345/271/263/345/217/260/350/257/225/347/224/250/344/270/216/345/217/221/350/241/214.md +1 -1
  4. package/README.md +8 -6
  5. package/README.zh-CN.md +2 -0
  6. package/api-contract.mjs +2 -1
  7. package/browser-extension/_locales/en/messages.json +8 -0
  8. package/browser-extension/_locales/zh_CN/messages.json +8 -0
  9. package/browser-extension/i18n.js +84 -0
  10. package/browser-extension/manifest.json +5 -4
  11. package/browser-extension/messages.js +266 -0
  12. package/browser-extension/newtab.css +4 -0
  13. package/browser-extension/newtab.html +9 -9
  14. package/browser-extension/newtab.js +38 -36
  15. package/browser-extension/page-locale.js +23 -0
  16. package/browser-extension/phase-labels.js +33 -6
  17. package/browser-extension/popup.css +2 -2
  18. package/browser-extension/popup.html +24 -26
  19. package/browser-extension/popup.js +72 -49
  20. package/browser-extension/tab-action.js +29 -24
  21. package/browser-extension/worker.js +29 -5
  22. package/browser-extension/workspace-title.js +2 -2
  23. package/build-profile.mjs +10 -2
  24. package/chromium-host.mjs +22 -11
  25. package/chromium-shell.mjs +5 -3
  26. package/cli.mjs +33 -30
  27. package/control.mjs +9 -8
  28. package/desktop/Info.plist +3 -1
  29. package/desktop/Launcher.m +10 -2
  30. package/desktop/OBControlBar.m +12 -8
  31. package/desktop/OBLocalization.h +20 -0
  32. package/desktop/OBPageView.m +2 -1
  33. package/desktop/WorkspacePanel.m +84 -83
  34. package/desktop/archive-release.py +5 -1
  35. package/desktop/build-macos.mjs +11 -5
  36. package/desktop/build-managed-input.mjs +2 -1
  37. package/desktop/build-portable.mjs +5 -3
  38. package/desktop/build-profile.mjs +2 -1
  39. package/desktop/build.mjs +2 -1
  40. package/desktop/create-shortcut.ps1 +7 -1
  41. package/desktop/en.lproj/Localizable.strings +106 -0
  42. package/desktop/install-menu-entry.mjs +2 -0
  43. package/desktop/notarize-macos.mjs +21 -24
  44. package/desktop/package-macos.mjs +4 -3
  45. package/desktop/sign.mjs +5 -4
  46. package/desktop/start-profile.mjs +2 -1
  47. package/desktop/start.mjs +3 -1
  48. package/desktop/verify-macos-release.mjs +9 -8
  49. package/desktop/zh-Hans.lproj/Localizable.strings +106 -0
  50. package/engine-service.mjs +1 -1
  51. package/hosted/cli.mjs +2 -1
  52. package/hosted/init.mjs +2 -1
  53. package/i18n.mjs +41 -0
  54. package/mcp-http.mjs +3 -2
  55. package/mcp-server.mjs +4 -3
  56. package/messages.zh-CN.mjs +175 -0
  57. package/package.json +4 -1
  58. package/page-activity.mjs +8 -6
  59. package/paths.mjs +2 -5
  60. package/runtime.mjs +4 -3
  61. package/sdk.mjs +40 -39
  62. package/service.mjs +2 -1
  63. package/skills/open-browser/SKILL.md +11 -9
  64. package/skills/open-browser/SKILL.zh-CN.md +22 -0
  65. package/skills/open-browser/references/macos.en.md +3 -0
  66. package/skills/open-browser/references/macos.md +2 -0
  67. package/skills/open-browser/references/operations.en.md +54 -0
  68. package/skills/open-browser/references/operations.md +2 -0
  69. package/skills/open-browser/references/recovery.en.md +36 -0
  70. package/skills/open-browser/references/recovery.md +2 -0
  71. package/skills/open-browser/references/windows.en.md +3 -0
  72. package/skills/open-browser/references/windows.md +2 -0
  73. package/skills/open-browser/scripts/bootstrap.mjs +6 -4
  74. package/skills/open-browser/scripts/guide.mjs +7 -4
  75. package/skills/open-browser/scripts/open-browser +5 -1
  76. package/studio/demo-site.mjs +5 -4
  77. package/studio/index.html +37 -33
  78. package/studio/index.mjs +10 -3
  79. package/studio/native-demo.mjs +8 -7
  80. package/studio/studio.css +3 -0
  81. package/studio/studio.js +98 -68
  82. package/system-i18n.mjs +19 -0
package/studio/studio.js CHANGED
@@ -1,26 +1,48 @@
1
1
  'use strict';
2
+
3
+ const { t, applyDocument, setLocale, messageLabels, bindLanguageSelect } = globalThis.openBrowserI18n;
4
+ setLocale(document.documentElement.lang);
5
+ applyDocument(document);
2
6
  const $ = id => document.getElementById(id);
3
7
  const state = { access: '', config: {}, workspaces: [], workspace: '', page: '', detail: null, demoRetry: null, demoOperations: new Set(), refreshId: 0, entered: false };
4
8
  const active = () => state.workspaces.find(w => w.workspaceId === state.workspace);
5
9
  const currentPage = () => active()?.pages.find(p => p.pageId === state.page);
6
- const timestamp = () => new Date().toLocaleTimeString('zh-CN', { hour12: false });
7
- const labels = { agent: 'Agent 控制', human: '用户控制', transferring: '交接中' };
8
- const groups = [
9
- { id: 'attention', title: '待处理' }, { id: 'running', title: 'Agent 运行' },
10
- { id: 'human', title: '人工接管' }, { id: 'idle', title: '待命' },
10
+ const timestamp = () => new Date().toLocaleTimeString(globalThis.openBrowserI18n.locale, { hour12: false });
11
+ const labels = messageLabels({ agent: "Agent in control", human: "User in control", transferring: "Transferring" });
12
+ const groups = () => [
13
+ { id: 'attention', title: t("Needs attention") }, { id: 'running', title: t("Agent running") },
14
+ { id: 'human', title: t("Take over") }, { id: 'idle', title: t("Idle") },
11
15
  ];
12
- const phases = { idle: '等待指令', queued: '已排队', running: '执行中', needs_credential: '等待凭据',
13
- completed: '已完成', failed: '执行失败', needs_visual_permission: '需要授权截图', cancelled: '已取消', outcome_unknown: '结果待核对' };
14
- const kinds = { openPage: '打开页面', observe: '观察页面', act: '页面操作' };
15
- const stepKinds = { click: '点击', fill: '填写', fillCredential: '填写凭据' };
16
- const errorText = {
17
- credential_required: '请补充缺少的凭据', wrong_password: '站点拒绝了账号或密码,请更新后再试。',
18
- pairing_failed: '管理入口已使用,请从 open-browser 重新打开控制台。',
19
- unauthorized: '管理入口已失效,请重新打开控制台。',
20
- origin_not_allowed: '新页面超出了当前工作区授权站点,请另建工作区。',
21
- login_form_changed: '登录表单已变化,请读取页面后再试。',
22
- human_control: '当前为用户控制,请先交回 Agent。',
23
- };
16
+ const phases = messageLabels({ idle: "Waiting for instructions", queued: "Queued", running: "Running", needs_credential: "Waiting for credentials",
17
+ completed: "Completed", failed: "Action failed", needs_visual_permission: "Screenshot permission required", cancelled: "Cancelled", outcome_unknown: "Result needs verification" });
18
+ const kinds = messageLabels({ openPage: "Open page", observe: "Observe page", act: "Page action" });
19
+ const stepKinds = messageLabels({ click: "Click", fill: "Fill", fillCredential: "Fill credential" });
20
+ const errorText = messageLabels({
21
+ credential_required: "Supply the missing credential.", wrong_password: "The site rejected the username or password. Update it and try again.",
22
+ pairing_failed: "This entry link has been used. Reopen the console from Open Browser.",
23
+ unauthorized: "This entry link has expired. Reopen the console.",
24
+ origin_not_allowed: "The new page is outside this workspace's allowed sites. Create another workspace.",
25
+ login_form_changed: "The sign-in form changed. Read the page and try again.",
26
+ human_control: "The user controls this workspace. Return control to the agent first.",
27
+ });
28
+
29
+ const showLanguage = bindLanguageSelect($('interface-language'), async preference => {
30
+ const settings = await post('/language', {preference});
31
+ updateLanguage(settings);
32
+ return settings;
33
+ }, notify);
34
+
35
+ function updateLanguage(settings) {
36
+ const changed = settings.locale !== globalThis.openBrowserI18n.locale;
37
+ setLocale(settings.locale);
38
+ showLanguage(settings);
39
+ if (!changed) return;
40
+ applyDocument(document);
41
+ paint();
42
+ if (!$('observed-at').textContent) clearObservation();
43
+ $('reveal').textContent = $('demo-secret').textContent ? t('Hide password') : t('Show password');
44
+ if ($('activity').querySelector('time')) $('activity-count').textContent = t('Records: {0}', $('activity').children.length);
45
+ }
24
46
 
25
47
  async function post(route, payload) {
26
48
  const headers = { 'Content-Type': 'application/json' };
@@ -31,7 +53,9 @@ async function post(route, payload) {
31
53
  return data;
32
54
  }
33
55
  async function call(method, params = {}) {
34
- return (await post('/call', { method, params })).result;
56
+ const data = await post('/call', { method, params });
57
+ updateLanguage(data.language);
58
+ return data.result;
35
59
  }
36
60
  function log(message) {
37
61
  const list = $('activity');
@@ -42,14 +66,14 @@ function log(message) {
42
66
  row.append(time, document.createTextNode(message));
43
67
  list.prepend(row);
44
68
  while (list.children.length > 20) list.lastElementChild.remove();
45
- $('activity-count').textContent = list.children.length + ' 条';
69
+ $('activity-count').textContent = t("Records: {0}", list.children.length);
46
70
  }
47
71
  function notify(message) {
48
72
  $('notice').textContent = message;
49
73
  $('notice').hidden = !message;
50
74
  }
51
75
  function clearObservation() {
52
- $('snapshot').textContent = '暂无观察结果';
76
+ $('snapshot').textContent = t("No observation yet");
53
77
  $('observed-at').textContent = '';
54
78
  }
55
79
  function choose(workspaceId) {
@@ -70,7 +94,7 @@ function clearSensitiveInputs() {
70
94
  $('credential-settings').open = false;
71
95
  $('demo-secret').textContent = '';
72
96
  $('demo-details').open = false;
73
- $('reveal').textContent = '显示密码';
97
+ $('reveal').textContent = t("Show password");
74
98
  }
75
99
  function groupOf(w) {
76
100
  if (w.mode === 'human' || w.mode === 'transferring') return 'human';
@@ -81,25 +105,25 @@ function groupOf(w) {
81
105
  }
82
106
  function describe(operation) {
83
107
  if (!operation) return '';
84
- const kind = kinds[operation.kind] || '操作';
85
- const status = operation.error === 'credential_required' ? '缺少凭据' :
108
+ const kind = kinds[operation.kind] || t("Action");
109
+ const status = operation.error === 'credential_required' ? t("Missing credential") :
86
110
  phases[operation.state] || operation.state;
87
111
  if (operation.state === 'running' && operation.stepKind) {
88
- return stepKinds[operation.stepKind] + ' · ' + operation.completedSteps + '/' + operation.totalSteps;
112
+ return (stepKinds[operation.stepKind] || kind) + ' · ' + operation.completedSteps + '/' + operation.totalSteps;
89
113
  }
90
114
  return [kind, status].filter(Boolean).join(' · ');
91
115
  }
92
116
  function shortState(w) {
93
117
  if (w.mode !== 'agent') return labels[w.mode];
94
118
  const a = w.activity || {};
95
- if (a.needsCredential) return '等待凭据';
96
- return describe(a.current) || phases[a.phase] || '等待指令';
119
+ if (a.needsCredential) return t("Waiting for credentials");
120
+ return describe(a.current) || phases[a.phase] || t("Waiting for instructions");
97
121
  }
98
122
  function paintRail() {
99
- const byGroup = new Map(groups.map(g => [g.id, []]));
123
+ const byGroup = new Map(groups().map(g => [g.id, []]));
100
124
  for (const w of state.workspaces) byGroup.get(groupOf(w)).push(w);
101
- const view = groups.map(g => ({ ...g, items: byGroup.get(g.id).map(w => ({
102
- id: w.workspaceId, name: w.name || '工作区', status: shortState(w),
125
+ const view = groups().map(g => ({ ...g, items: byGroup.get(g.id).map(w => ({
126
+ id: w.workspaceId, name: w.name || t("Workspace"), status: shortState(w),
103
127
  pages: w.pages.length, selected: w.workspaceId === state.workspace,
104
128
  })) }));
105
129
  const rail = $('workspaces');
@@ -131,7 +155,7 @@ function paintRail() {
131
155
  const name = document.createElement('b');
132
156
  name.textContent = row.name;
133
157
  const status = document.createElement('small');
134
- status.textContent = row.status + ' · ' + row.pages + ' 页';
158
+ status.textContent = row.status + ' · ' + t("Pages: {0}", row.pages);
135
159
  item.append(name, status);
136
160
  item.onclick = () => { if (state.workspace !== row.id) { choose(row.id); sync(); } };
137
161
  block.append(item);
@@ -163,12 +187,12 @@ function paintCredential() {
163
187
  if (!request) return;
164
188
  const demoPassword = request.origin === new URL(state.config.demoUrl).origin && request.credentialRef === 'demo.password';
165
189
  const canContinue = state.demoOperations.has(request.operationId);
166
- $('credential-title').textContent = demoPassword ? '需要补充密码' : '需要补充凭据';
190
+ $('credential-title').textContent = demoPassword ? t("Password needed") : t("Credential needed");
167
191
  $('credential-ref').textContent = request.credentialRef;
168
192
  $('credential-origin').textContent = request.origin;
169
- $('credential-label').textContent = demoPassword ? '密码' : '凭据值';
193
+ $('credential-label').textContent = demoPassword ? t("Password") : t("Credential value");
170
194
  $('insert-password').hidden = !demoPassword;
171
- $('submit-credential').textContent = canContinue ? '补充并继续' : '绑定凭据';
195
+ $('submit-credential').textContent = canContinue ? t("Supply and continue") : t("Bind credential");
172
196
  }
173
197
  function paint() {
174
198
  paintRail();
@@ -176,15 +200,15 @@ function paint() {
176
200
  $('new-view').hidden = Boolean(w);
177
201
  $('active-view').hidden = !w;
178
202
  if (!w) return;
179
- $('workspace-name').textContent = w.name || '工作区';
203
+ $('workspace-name').textContent = w.name || t("Workspace");
180
204
  $('wid').title = w.workspaceId;
181
205
  $('mode').textContent = labels[w.mode] || w.mode;
182
206
  const a = w.activity || {};
183
- $('work-state').textContent = w.mode === 'human' ? '自动化已暂停' :
184
- w.mode === 'transferring' ? '正在交接' : a.needsCredential ? '等待补充凭据' :
185
- describe(a.current) || '等待指令';
186
- if (w.mode === 'agent' && a.queued > 0) $('work-state').textContent += ' · 排队 ' + a.queued;
187
- $('result-text').textContent = describe(a.recent) || '暂无已结束操作';
207
+ $('work-state').textContent = w.mode === 'human' ? t("Automation paused") :
208
+ w.mode === 'transferring' ? t("Transferring control…") : a.needsCredential ? t("Waiting for a credential") :
209
+ describe(a.current) || t("Waiting for instructions");
210
+ if (w.mode === 'agent' && a.queued > 0) $('work-state').textContent = t("{0} · Queued: {1}", $('work-state').textContent, a.queued);
211
+ $('result-text').textContent = describe(a.recent) || t("No completed actions");
188
212
  $('take').hidden = w.mode !== 'agent' || !w.pages.length;
189
213
  $('give').hidden = w.mode !== 'human';
190
214
  $('view-controlled').hidden = w.mode !== 'human' || !w.pages.length;
@@ -207,7 +231,7 @@ function paint() {
207
231
  state.page = fallback;
208
232
  }
209
233
  if (pages.value !== state.page) pages.value = state.page;
210
- $('wid').textContent = [currentPage()?.origin, w.pages.length + ' 个页面'].filter(Boolean).join(' · ');
234
+ $('wid').textContent = [currentPage()?.origin, t("Pages in workspace: {0}", w.pages.length)].filter(Boolean).join(' · ');
211
235
  const isDemo = currentPage()?.origin === new URL(state.config.demoUrl).origin;
212
236
  $('login-action').hidden = !isDemo || w.mode !== 'agent';
213
237
  $('demo-details').hidden = !isDemo;
@@ -221,7 +245,7 @@ function paint() {
221
245
  }
222
246
  function setConnected(connected) {
223
247
  $('connection-status').dataset.connected = String(connected);
224
- $('connection').textContent = connected ? '本机服务已连接' : '服务已断开';
248
+ $('connection').textContent = connected ? t("Local service connected") : t("Service disconnected");
225
249
  }
226
250
  async function refresh() {
227
251
  const sequence = ++state.refreshId;
@@ -252,7 +276,7 @@ function command(id, fn, event = 'click') {
252
276
  notify('');
253
277
  try { await fn(); }
254
278
  catch (err) {
255
- const msg = errorText[err.message] || '操作未完成(' + err.message + ')';
279
+ const msg = errorText[err.message] || t("Action did not complete ({0})", err.message);
256
280
  notify(msg);
257
281
  log(msg);
258
282
  } finally {
@@ -273,13 +297,13 @@ async function create(name, url) {
273
297
  choose(workspaceId);
274
298
  state.page = page.pageId;
275
299
  paint();
276
- log('已打开「' + name + '」');
300
+ log(t("Opened “{0}”", name));
277
301
  return { workspaceId, pageId: page.pageId };
278
302
  }
279
303
  async function observe(page, method = 'observe') {
280
304
  const snap = await call(method, page);
281
305
  if (state.workspace === page.workspaceId && state.page === page.pageId) {
282
- $('snapshot').textContent = snap.text || (snap.elements || []).map(e => e.role + ' ' + e.name).join('\n') || '当前页无可见文本';
306
+ $('snapshot').textContent = snap.text || (snap.elements || []).map(e => e.role + ' ' + e.name).join('\n') || t("No visible text on this page");
283
307
  $('observed-at').textContent = timestamp();
284
308
  }
285
309
  return snap;
@@ -289,17 +313,22 @@ async function putCredential(page, credentialRef, value) {
289
313
  }
290
314
  async function runLogin(page) {
291
315
  const snap = await observe(page);
292
- const authenticated = observation => observation.text.includes('我的账号') &&
293
- observation.elements.some(e => e.role === 'button' && e.name === '退出登录');
316
+ // A demo document keeps its language if the console switches mid-sign-in.
317
+ const matches = (value, source, exact = true) => ['en','zh-CN'].some(language => {
318
+ const text = globalThis.openBrowserI18n.translate(language, source);
319
+ return exact ? value === text : value.includes(text);
320
+ });
321
+ const authenticated = observation => matches(observation.text, 'My account', false) &&
322
+ observation.elements.some(e => e.role === 'button' && matches(e.name, 'Sign out'));
294
323
  if (authenticated(snap)) {
295
324
  state.demoRetry = null;
296
- log('已读取受保护的账号页面');
325
+ log(t("Read the signed-in account page"));
297
326
  return;
298
327
  }
299
- const find = (role, name) => snap.elements.find(element => element.role === role && element.name === name)?.ref;
300
- const username = find('textbox', '账号');
301
- const password = find('textbox', '密码');
302
- const submit = find('button', '登录');
328
+ const find = (role, name) => snap.elements.find(element => element.role === role && matches(element.name, name))?.ref;
329
+ const username = find('textbox', 'Username');
330
+ const password = find('textbox', 'Password');
331
+ const submit = find('button', 'Sign in');
303
332
  if (!username || !password || !submit) throw new Error('login_form_changed');
304
333
  const request = {
305
334
  workspaceId: page.workspaceId, pageId: page.pageId, documentId: snap.documentId,
@@ -318,12 +347,12 @@ async function runLogin(page) {
318
347
  receipt = await call('getOperation', { workspaceId: page.workspaceId, operationId: request.operationId });
319
348
  }
320
349
  if (receipt.error === 'credential_required' && receipt.credentialRef === 'demo.password') {
321
- log('任务等待补充密码');
350
+ log(t("Task is waiting for a password"));
322
351
  return;
323
352
  }
324
353
  if (receipt.state !== 'completed') throw new Error(receipt.error || receipt.state);
325
354
  const after = await observe(page);
326
- if (after.text.includes('账号或密码不正确')) {
355
+ if (matches(after.text, 'Incorrect username or password', false)) {
327
356
  state.demoRetry = { ...page, operationId: request.operationId, credentialRef: 'demo.password', origin: new URL(state.config.demoUrl).origin };
328
357
  paint();
329
358
  throw new Error('wrong_password');
@@ -331,10 +360,10 @@ async function runLogin(page) {
331
360
  if (!authenticated(after))
332
361
  throw new Error('account_page_unconfirmed');
333
362
  state.demoRetry = null;
334
- log('登录成功,已读取受保护的账号页面');
363
+ log(t("Signed in and read the account page"));
335
364
  }
336
365
  async function demo(withPassword) {
337
- const page = await create(withPassword ? '自动登录' : '凭据补充', state.config.demoUrl);
366
+ const page = await create(withPassword ? t("Automatic sign-in") : t("Supply a missing credential"), state.config.demoUrl);
338
367
  await putCredential(page, 'demo.username', state.config.username);
339
368
  if (withPassword) await putCredential(page, 'demo.password', (await post('/demo-password', {})).password);
340
369
  await runLogin(page);
@@ -344,10 +373,10 @@ function pageHandle() {
344
373
  }
345
374
 
346
375
  command('show-new', () => choose(''));
347
- command('new-form', () => create($('name').value.trim() || '我的工作区', $('url').value), 'submit');
376
+ command('new-form', () => create($('name').value.trim() || t("My workspace"), $('url').value), 'submit');
348
377
  command('demo', () => demo(true));
349
378
  command('missing', () => demo(false));
350
- command('observe', async () => { await observe(pageHandle(), 'previewPage'); log('已读取当前页面'); });
379
+ command('observe', async () => { await observe(pageHandle(), 'previewPage'); log(t("Read the current page")); });
351
380
  command('login-action', () => runLogin(pageHandle()));
352
381
  command('insert-password', async () => { $('password').value = (await post('/demo-password', {})).password; });
353
382
  command('credential-form', async () => {
@@ -367,7 +396,7 @@ command('credential-form', async () => {
367
396
  if (state.demoOperations.has(req.operationId)) {
368
397
  state.demoRetry = null;
369
398
  await runLogin({ workspaceId: req.workspaceId, pageId: req.pageId });
370
- } else log('已绑定缺少的凭据;调用方可重新观察并提交剩余操作');
399
+ } else log(t("Credential bound. The agent can observe again and submit the remaining actions."));
371
400
  }, 'submit');
372
401
  command('bind-form', async () => {
373
402
  const page = currentPage();
@@ -375,39 +404,39 @@ command('bind-form', async () => {
375
404
  $('bind-value').value = '';
376
405
  await call('setCredential', { workspaceId: state.workspace, origin: page.origin, credentialRef: $('bind-id').value, value });
377
406
  $('credential-settings').open = false;
378
- log('已为当前工作区绑定站点凭据');
407
+ log(t("Credential bound to the site in this workspace"));
379
408
  }, 'submit');
380
409
  command('take', async () => {
381
410
  await call('takeControl', pageHandle());
382
411
  clearObservation();
383
- log('已由用户控制当前工作区');
412
+ log(t("You now control this workspace"));
384
413
  });
385
414
  command('give', async () => {
386
415
  await call('returnToAgent', { workspaceId: state.workspace });
387
416
  clearObservation();
388
- log('已交回 Agent,页面需要重新观察');
417
+ log(t("Control returned to the agent. Observe the page again."));
389
418
  });
390
419
  command('view-controlled', async () => {
391
420
  await call('showPage', pageHandle());
392
- log('已显示接管页面');
421
+ log(t("Displayed the controlled page"));
393
422
  });
394
423
  command('close-workspace', async () => {
395
424
  await call('closeWorkspace', { workspaceId: state.workspace });
396
425
  if (state.demoRetry?.workspaceId === state.workspace) state.demoRetry = null;
397
426
  choose('');
398
- log('工作区已关闭');
427
+ log(t("Workspace closed"));
399
428
  });
400
429
  command('page-form', async () => {
401
430
  const page = await call('openPage', { workspaceId: state.workspace, url: $('address').value });
402
431
  state.page = page.pageId;
403
432
  $('address').value = '';
404
433
  clearObservation();
405
- log('已打开新页面');
434
+ log(t("Opened a new page"));
406
435
  }, 'submit');
407
436
  command('reveal', async () => {
408
437
  const showing = Boolean($('demo-secret').textContent);
409
438
  $('demo-secret').textContent = showing ? '' : (await post('/demo-password', {})).password;
410
- $('reveal').textContent = showing ? '显示密码' : '隐藏密码';
439
+ $('reveal').textContent = showing ? t("Show password") : t("Hide password");
411
440
  });
412
441
  $('pages').onchange = () => { state.page = $('pages').value; clearObservation(); paint(); };
413
442
 
@@ -419,20 +448,21 @@ $('pages').onchange = () => { state.page = $('pages').value; clearObservation();
419
448
  sessionStorage.setItem('open-browser.studio', state.access);
420
449
  } else state.access = sessionStorage.getItem('open-browser.studio') || '';
421
450
  state.config = await post('/config', {});
451
+ updateLanguage(state.config.language);
422
452
  $('demo-user').textContent = state.config.username;
423
453
  $('url').value = state.config.demoUrl;
424
454
  state.workspace = sessionStorage.getItem('open-browser.selection') || '';
425
455
  await refresh();
426
456
  if (!state.workspace && !sessionStorage.getItem('open-browser.selection') &&
427
457
  state.workspaces.length && !state.entered) {
428
- const first = groups.flatMap(g => state.workspaces.filter(w => groupOf(w) === g.id))[0];
458
+ const first = groups().flatMap(g => state.workspaces.filter(w => groupOf(w) === g.id))[0];
429
459
  choose(first.workspaceId);
430
460
  await refresh();
431
461
  }
432
462
  setInterval(() => { if (!document.hidden) sync(); }, 900);
433
463
  document.addEventListener('visibilitychange', () => { if (!document.hidden) sync(); });
434
464
  })().catch(error => {
435
- $('connection').textContent = '未连接';
436
- notify(errorText[error.message] || '无法连接本机控制台,请重新启动 open-browser。');
465
+ $('connection').textContent = t("Disconnected");
466
+ notify(errorText[error.message] || t("Could not connect to the local console. Restart Open Browser."));
437
467
  document.querySelectorAll('button,input,select').forEach(el => el.disabled = true);
438
468
  });
@@ -0,0 +1,19 @@
1
+ import './browser-extension/messages.js';
2
+ import './browser-extension/i18n.js';
3
+ import chinese from './messages.zh-CN.mjs';
4
+
5
+ const i18n = globalThis.openBrowserI18n;
6
+ export const systemLocale = i18n.resolveLocale(process.env.OPEN_BROWSER_SYSTEM_LOCALE ||
7
+ process.env.LC_ALL || process.env.LC_MESSAGES || process.env.LANG || Intl.DateTimeFormat().resolvedOptions().locale);
8
+ export const localeOverride = process.env.OPEN_BROWSER_LOCALE?.trim()
9
+ ? i18n.resolveLocale(process.env.OPEN_BROWSER_LOCALE) : undefined;
10
+
11
+ export function translate(language, message, ...args) {
12
+ if (language === 'zh-CN' && Object.hasOwn(chinese, message)) return i18n.format(chinese[message], args);
13
+ return i18n.translate(language, message, ...args);
14
+ }
15
+
16
+ // Bootstrap commands use this before they select a build or state directory.
17
+ export function systemMessage(message, ...args) {
18
+ return translate(localeOverride || systemLocale, message, ...args);
19
+ }