Files
Reims-Go/frontend/src/lib/optimizations.ts
T
Dnyo666 ceeec602be feat(i18n,plugin): implement end-to-end i18n & L10n v2 architecture and language pack protocol
- Build single-source-of-truth 7-domain locale catalog (`locales/{zh-CN,en-US}/*.json`, 1,100+ keys) and `cmd/i18ngen` generator emitting Go catalogs and eager/lazy-split TypeScript domain modules (`core`/`vm` eager; `wizard`/`settings`/`plugins` lazy)
- Add zero-dependency ICU MessageFormat subset (`{var}`, `{n, number}`, CLDR `plural`, `select`), 8-hop cycle-free regional fallback (`zh-HK/zh-MO -> zh-Hant -> zh-TW -> zh-CN`), `auto` OS display-language preference, and `en-XA` pseudo-localization across Go and TypeScript
- Introduce `CodedError` supportability with `[E_CODE]` badges, collapsible `[detail]` diagnostics, and automatic SMC OSK / SMBIOS serial / MAC / token redaction
- Add Host × Guest macOS dual-terminology annotation (`FormatGuestTerm`) across 6 official Apple guest UI locales and localize Win32 system tray, file pickers, and DPI-adaptive `installguide` overlays with CJK font fallback probing
- Upgrade L1–L4 plugin localization to dual-track v2: Track A full language packs (`files`, WOFF2 `fonts`, cross-plugin `pluginOverrides`), Track B plugin-scoped `l10n` bundles (`HasUIMessages` isolation), live `plugin/localeChanged` notifications, `< 2ms` static CLI pack loading, and `reims-go plugin locale init|check` translator toolchain with `zh-TW` and `ja-JP` reference packs
- Harden security, WCAG 2.1 AA token contrast, `< 768px` responsive drawer & form layouts, and RTL logical properties; add backend security/locale regression tests and frontend `node --test` static/runtime guard suite in CI

# Conflicts:
#	frontend/src/i18n.ts
#	internal/cli/cli.go
#	internal/i18n/i18n.go
2026-11-30 14:56:19 +08:00

64 lines
2.3 KiB
TypeScript

import '../i18n/domains/settings.gen'
import { I18nKey, t } from '../i18n'
import { Locale, Optimization, OptimizationStatus } from '../types'
export type KernelIrqchipMode = 'auto' | 'on' | 'off'
export function findOptimization(list: Optimization[] | undefined, id: string): Optimization | undefined {
return (list ?? []).find((o) => o.id === id)
}
export function optBadgeClass(status: OptimizationStatus | undefined): string {
switch (status) {
case 'recommended':
case 'auto':
return 'badge-ok'
case 'experimental':
return 'badge-warn'
case 'available':
return 'badge-accent'
default:
return ''
}
}
export function optStatusLabel(locale: Locale, status: OptimizationStatus | undefined): string {
const keyMap: Record<OptimizationStatus, I18nKey> = {
recommended: 'optRecommended',
available: 'optAvailable',
experimental: 'optExperimental',
auto: 'optAuto',
unavailable: 'optUnavailable',
}
return t(locale, keyMap[status ?? 'unavailable'])
}
export function kernelIrqchipHint(locale: Locale, opt: Optimization | undefined): string {
if (!opt) return t(locale, 'optKernelIrqchipUnavailable')
if (opt.status === 'recommended') return t(locale, 'optKernelIrqchipRec')
if (opt.status === 'experimental') return t(locale, 'optKernelIrqchipExp')
if (opt.detail === 'win10-needs-patch') return t(locale, 'optKernelIrqchipWin10NoPatch')
if (opt.detail && opt.detail.startsWith('0x')) return t(locale, 'optKernelIrqchipNestedErr', { code: opt.detail })
return t(locale, 'optKernelIrqchipUnavailable')
}
const IRQCHIP_RE = /(?:^|\s)-machine\s+kernel-irqchip=(on|off)(?=\s|$)/i
const INLINE_IRQCHIP_RE = /\bkernel-irqchip=(on|off)\b/i
export function parseKernelIrqchip(extraArgs: string | undefined): KernelIrqchipMode {
const raw = (extraArgs ?? '').trim()
const m = raw.match(IRQCHIP_RE) ?? raw.match(INLINE_IRQCHIP_RE)
if (!m) return 'auto'
return m[1].toLowerCase() === 'on' ? 'on' : 'off'
}
export function applyKernelIrqchip(extraArgs: string | undefined, mode: KernelIrqchipMode): string {
const cleaned = (extraArgs ?? '')
.replace(/(?:^|\s)-machine\s+kernel-irqchip=(?:on|off)(?=\s|$)/gi, ' ')
.replace(/\s+/g, ' ')
.trim()
if (mode === 'auto') return cleaned
const flag = `-machine kernel-irqchip=${mode}`
return cleaned ? `${cleaned} ${flag}` : flag
}