Files
magpie/internal/gui/intl_lang_test.go
T
yetone 31c1e3ab1c gui: dates, times and numbers read in the GUI's language, not the system's, so a Chinese Mac set to English no longer shows Routing's days as 10月11日 周日 (#1843)
What changed: intlLang() was the GUI's tag for Intl, but returned
undefined for English ("the system's own formats"), and about 60 calls
in app.js, routing.js, library.js, plugins.js, caller-keys.js and
context.js formatted with no locale, [] or undefined anyway. All of
those follow the system's locale, so with magpie set to English on a
zh-CN Mac, Routing's day pills read "10月11日 周日" (the report), and so
did request times, reset/until titles on Accounts and Usage, plugin and
library dates, the restore notice, and key rest times. Now intlLang()
always returns a tag: zh-CN, zh-TW, ja-JP, de-DE for those languages,
and for English the system's own English (en-GB keeps day-month) or
plain "en" on a system in another language. Every date, time and number
formatting call in the assets takes intlLang(); the `intlLang() || "en"`
and `documentElement.lang || undefined` variants are folded into it.
<html lang> stays "en" for English. Routing's clock formatters, made
once, are made again when the language changes.

Tests: dates-gui-lang.test.cjs runs English on a zh-CN browser, English
on en-GB, and zh, zh-TW, ja, de on en-US, in Chromium and WebKit at
1100 and 390px: Routing's day pills (in the bar and under its menu) and
a request's time must read in the GUI's tag and not the browser's.
TestDatesFollowGUILanguage (Go, so CI runs it) fails on any formatting
call in the assets given no locale, [] or undefined.
github-token and reset-each-title computed their expected text in the
browser's locale, i.e. they encoded the bug for zh/ja/de; they now ask
intlLang().

Run: with routing.js put back to origin/main the new GUI test fails 10
of 12 (all but en-GB, where the system's English is right either way);
with intlLang() returning undefined for English the English cases fail.
TestDatesFollowGUILanguage fails on origin/main's routing.js (lines 244,
688, 1925, 2230, ...) and passes on the fix. gofmt -l clean; go vet
./internal/gui on darwin, GOOS=linux -tags nogui and GOOS=windows ok;
go test -tags nogui ./internal/gui ok. Full GUI suite (621 files,
concurrency 6): 51 failures in 21 files; rerun alone, the same 8 files
fail the same way on an origin/main 552e974f2 copy (gui-ja,
library-mcp-tools, pick-skills, profile-in-use, routing-group-fold,
routing-sessions, searcher-pick, text-size), signin-proxy failed once
under load ("element was detached", de 380) and passes 3/3 alone, the
rest pass.
Not run: not tried in the real app on a zh-CN Mac; no Windows or Linux
webview run.
2026-10-13 02:14:10 +08:00

35 lines
1.2 KiB
Go

package gui
import (
"os"
"path/filepath"
"regexp"
"strings"
"testing"
)
// TestDatesFollowGUILanguage: every date, time and number the GUI formats
// is given intlLang(), the GUI's language. With no locale, [] or undefined
// it follows the system instead, and a Chinese Mac set to English read
// Routing's days as "10月11日 周日" (#1843). The browser test
// dates-gui-lang.test.cjs checks what Routing shows; this keeps every other
// call from slipping back, since CI doesn't run the browser tests.
func TestDatesFollowGUILanguage(t *testing.T) {
bare := regexp.MustCompile(`\.toLocale(Date|Time)?String\(\s*(\)|\[\]|undefined\b|document\.documentElement\.lang)|new Intl\.\w+\(\s*(\)|\[\]|undefined\b)|intlLang\(\) \|\|`)
files, err := filepath.Glob(filepath.Join("assets", "*.js"))
if err != nil || len(files) == 0 {
t.Fatalf("no assets: %v", err)
}
for _, f := range files {
b, err := os.ReadFile(f)
if err != nil {
t.Fatal(err)
}
for i, line := range strings.Split(string(b), "\n") {
if bare.MatchString(line) {
t.Errorf("%s:%d formats in the system's locale, not the GUI's: give it intlLang()\n\t%s", f, i+1, strings.TrimSpace(line))
}
}
}
}