Files
hermes-ui/packages/client/src/i18n/index.ts
T
toor c93e1fe1bd
Build / build (push) Canceled after 0s
NPM Lockfile Check / npm ci --ignore-scripts (push) Canceled after 0s
Playwright / e2e (push) Canceled after 0s
Phase 002: rebrand to hermes-ui and consolidate i18n to zh/en
Removes the ekko / hermes-web-ui branding from the whole tree and drops
eight locale files, so the project presents one name and one language pair.

Data compatibility is deliberate, not accidental: DB filenames, the JWT
audience, and skill manifest ownership all still recognise their pre-rename
values so existing deployments under ~/.hermes-web-ui keep working without a
re-login or a re-injection.

scripts/harness-check.mjs now scans for the legacy strings and fails the
build on any new occurrence, with an explicit allow-list (and reasons) for
the compatibility paths that must keep them.
2026-10-16 11:11:29 +08:00

42 lines
1.2 KiB
TypeScript

import { createI18n } from 'vue-i18n'
import { messages, supportedLocales } from './messages'
import type { SupportedLocale } from './messages'
const saved = localStorage.getItem('hermes_locale')
function normalize(tag: string): SupportedLocale {
return tag.toLowerCase().startsWith('zh') ? 'zh' : 'en'
}
function resolveLocale(saved: string | null): SupportedLocale {
if (saved && (supportedLocales as readonly string[]).includes(saved)) {
return saved as SupportedLocale
}
// A locale stored before the zh/en-only consolidation (for example 'zh-TW'
// or 'ja') is no longer supported; remap it instead of dropping to English.
if (saved) return normalize(saved)
const preferred = navigator.languages[0]
return preferred ? normalize(preferred) : 'en'
}
function setHtmlLang(locale: SupportedLocale) {
document.documentElement.lang = locale
}
const locale = resolveLocale(saved)
setHtmlLang(locale)
export const i18n = createI18n({
legacy: false,
locale,
fallbackLocale: 'en',
messages,
})
export function switchLocale(newLocale: string): void {
;(i18n.global.locale as any).value = newLocale
setHtmlLang(newLocale as SupportedLocale)
}