mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-27 01:19:25 +08:00
feat(panel): modularize 3-tab preferences, add model context windows, and optimize telemetry
- Refactor Preferences into decoupled General, Structure, and Other tabs with unified settings schema, factory reset, and trajectory cache rebuild endpoints - Extract standalone widget, metric, and step-table column registries to customize topbar/composer slots, hover popup modules, live overview layout, and step detail columns - Add bilingual zh-CN/en-US i18n dictionaries, theme accent presets, and font scale controls across Shadow DOM overlay and sidebar views - Support per-model host-advertised context window rules across App and IDE transports - Preserve CLEARED step generation timings, memoize per-poll model resolution, optimize LOESS sorted-x fitting, and update bilingual READMEs and test suites
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* @fileoverview Reactive lightweight i18n engine (`zh-CN` / `en-US` / `auto`).
|
||||
* Default language is `'zh-CN'` so out-of-the-box UI matches existing behavior 100%.
|
||||
*/
|
||||
|
||||
import { createReactiveStore } from '../core/reactive.js';
|
||||
import { I18N_MESSAGES_ZH_CN } from './zh-CN.js';
|
||||
import { I18N_MESSAGES_EN_US } from './en-US.js';
|
||||
|
||||
export const I18N_DICTIONARIES = Object.freeze({
|
||||
'zh-CN': I18N_MESSAGES_ZH_CN,
|
||||
'en-US': I18N_MESSAGES_EN_US,
|
||||
});
|
||||
|
||||
export function normalizeI18nLanguage(raw) {
|
||||
const val = String(raw ?? '').trim();
|
||||
if (val === 'auto') return 'auto';
|
||||
if (/^en(?:-|$)/i.test(val)) return 'en-US';
|
||||
if (/^zh(?:-|$)/i.test(val)) return 'zh-CN';
|
||||
return 'zh-CN';
|
||||
}
|
||||
|
||||
export function detectHostSystemLocale() {
|
||||
try {
|
||||
if (typeof navigator !== 'undefined' && navigator.language) {
|
||||
return String(navigator.language).toLowerCase().startsWith('zh') ? 'zh-CN' : 'en-US';
|
||||
}
|
||||
} catch {
|
||||
// Ignore environment navigator read errors
|
||||
}
|
||||
return 'zh-CN';
|
||||
}
|
||||
|
||||
export const i18nStore = createReactiveStore({
|
||||
language: 'zh-CN',
|
||||
locale: 'zh-CN',
|
||||
});
|
||||
|
||||
export function setI18nLanguage(rawLang) {
|
||||
const language = normalizeI18nLanguage(rawLang);
|
||||
const locale = language === 'auto' ? detectHostSystemLocale() : language;
|
||||
const cur = i18nStore.getState();
|
||||
if (cur.language !== language || cur.locale !== locale) {
|
||||
i18nStore.setState({ language, locale });
|
||||
}
|
||||
return locale;
|
||||
}
|
||||
|
||||
export function getEffectiveLocale() {
|
||||
return i18nStore.getState().locale || 'zh-CN';
|
||||
}
|
||||
|
||||
export function isEnglishLocale() {
|
||||
return getEffectiveLocale() === 'en-US';
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a message key with optional `{name}` variable interpolation.
|
||||
*
|
||||
* @param {string} key
|
||||
* @param {Record<string, string | number>} [vars]
|
||||
* @returns {string}
|
||||
*/
|
||||
export function t(key, vars = undefined) {
|
||||
const locale = getEffectiveLocale();
|
||||
const dict = I18N_DICTIONARIES[locale] || I18N_MESSAGES_ZH_CN;
|
||||
const template = dict[key] ?? I18N_MESSAGES_ZH_CN[key] ?? key;
|
||||
if (!vars || typeof template !== 'string') return template;
|
||||
return template.replace(/\{(\w+)\}/g, (_, k) =>
|
||||
vars[k] !== undefined && vars[k] !== null ? String(vars[k]) : ''
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user