- 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
107 lines
3.4 KiB
Go
107 lines
3.4 KiB
Go
//go:build windows
|
|
|
|
package host
|
|
|
|
import (
|
|
"strings"
|
|
"sync"
|
|
"syscall"
|
|
"unicode/utf16"
|
|
"unsafe"
|
|
|
|
"github.com/Nwflower/reims-go/internal/i18n"
|
|
)
|
|
|
|
var (
|
|
modGDI32Font = syscall.NewLazyDLL("gdi32.dll")
|
|
modUser32Font = syscall.NewLazyDLL("user32.dll")
|
|
procEnumFontFamiliesEx = modGDI32Font.NewProc("EnumFontFamiliesExW")
|
|
procGetDCFont = modUser32Font.NewProc("GetDC")
|
|
procReleaseDCFont = modUser32Font.NewProc("ReleaseDC")
|
|
|
|
fontDetectMu sync.Mutex
|
|
fontDetectHit bool
|
|
fontDetectMemo = map[string]bool{}
|
|
fontDetectCB = syscall.NewCallback(func(lpelfe, lpntme, fontType, lparam uintptr) uintptr {
|
|
fontDetectHit = true
|
|
return 0
|
|
})
|
|
)
|
|
|
|
type gdiLogFontW struct {
|
|
height, width, escapement, orientation, weight int32
|
|
italic, underline, strikeOut, charSet byte
|
|
outPrecision, clipPrecision, quality, pitchFam byte
|
|
face [32]uint16
|
|
}
|
|
|
|
func hasInstalledFontFamily(name string) bool {
|
|
fontDetectMu.Lock()
|
|
defer fontDetectMu.Unlock()
|
|
if ok, cached := fontDetectMemo[name]; cached {
|
|
return ok
|
|
}
|
|
dc, _, _ := procGetDCFont.Call(0)
|
|
if dc == 0 {
|
|
return true // fail-open if desktop DC unavailable
|
|
}
|
|
defer procReleaseDCFont.Call(0, dc)
|
|
|
|
var lf gdiLogFontW
|
|
lf.charSet = 1 // DEFAULT_CHARSET
|
|
u16 := utf16.Encode([]rune(name))
|
|
if len(u16) >= len(lf.face) {
|
|
u16 = u16[:len(lf.face)-1]
|
|
}
|
|
copy(lf.face[:], u16)
|
|
|
|
fontDetectHit = false
|
|
procEnumFontFamiliesEx.Call(dc, uintptr(unsafe.Pointer(&lf)), fontDetectCB, 0, 0)
|
|
if fontDetectHit {
|
|
// Only memoize positive hits so installing Windows FoD fonts at runtime
|
|
// clears the missing-font hint without restarting Reims-Go.
|
|
fontDetectMemo[name] = true
|
|
}
|
|
return fontDetectHit
|
|
}
|
|
|
|
// CheckMissingLocaleFonts checks whether Windows has at least one modern UI
|
|
// font installed for the East Asian script required by locale (detecting missing
|
|
// Windows Features-on-Demand supplemental font packages on non-CJK Windows installs).
|
|
// Returns "" when fonts are present or not needed, or a localized script label.
|
|
func CheckMissingLocaleFonts(locale string) string {
|
|
return CheckMissingLocaleFontsForUI(locale, i18n.ResolveLocale(locale))
|
|
}
|
|
|
|
// CheckMissingLocaleFontsForUI checks whether Windows has fonts for targetLocale
|
|
// and returns the localized script name in uiLocale when missing.
|
|
func CheckMissingLocaleFontsForUI(targetLocale string, uiLocale i18n.Locale) string {
|
|
low := strings.ToLower(strings.TrimSpace(targetLocale))
|
|
var candidates []string
|
|
var scriptKey string
|
|
|
|
switch {
|
|
case low == "zh-tw" || low == "zh-hk" || low == "zh-mo" || strings.HasPrefix(low, "zh-hant"):
|
|
scriptKey = "font.script.zh_hant"
|
|
candidates = []string{"Microsoft JhengHei UI", "Microsoft JhengHei", "Noto Sans TC", "PingFang TC", "Source Han Sans TC"}
|
|
case strings.HasPrefix(low, "zh"):
|
|
scriptKey = "font.script.zh_hans"
|
|
candidates = []string{"Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans SC", "PingFang SC", "HarmonyOS Sans SC", "MiSans"}
|
|
case strings.HasPrefix(low, "ja"):
|
|
scriptKey = "font.script.ja"
|
|
candidates = []string{"Yu Gothic UI", "Yu Gothic", "Meiryo UI", "Meiryo", "BIZ UDPGothic", "Noto Sans JP"}
|
|
case strings.HasPrefix(low, "ko"):
|
|
scriptKey = "font.script.ko"
|
|
candidates = []string{"Malgun Gothic", "Noto Sans KR", "Apple SD Gothic Neo"}
|
|
default:
|
|
return ""
|
|
}
|
|
|
|
for _, f := range candidates {
|
|
if hasInstalledFontFamily(f) {
|
|
return ""
|
|
}
|
|
}
|
|
return i18n.T(uiLocale, scriptKey)
|
|
}
|