Settings → Language offers 繁體中文 beside 简体中文. On System, a browser or OS locale of zh-TW, zh-HK, zh-MO or zh-Hant (zh_TW.UTF-8 too) shows zh-TW; zh-CN, zh-SG and zh-Hans-HK keep Simplified. The tray menu and quota alerts follow the same choice. Release notes fall back to Simplified. The zh-TW strings are generated from the zh strings with opencc (cn→twp), then corrected to Taiwan wording: 設定, 檔案, 帳號, 伺服器, 預設, 閘道, 連接埠, 參數, 選單, 透過, 取得, 用戶端, 存取, 終端機, 「」 quotes. A quota window is 時段 and a context window stays 上下文視窗. Number units use 萬/億, and #unitsRow is shown for zh-TW. Verified: - New gui-zh-tw.test.cjs, in Chromium and WebKit: - key parity, placeholders and tags against zh; - no Simplified characters; - the Taiwan words; - locale detection for each system tag; - <html lang>, nav labels, fmtN units, the picker; - Settings Language at 1000px and 440px. With the sysLocale zh-TW line removed, it fails. On the base assets, all 3 fail. - gui-ja, gui-de and i18n-keys pass. - go vet, and go test -tags nogui for ./internal/gui and ./internal/settings, pass. That includes the new zh-TW cases in TestTrayLang / TestTrayLabels / quota_alert_test, which fail without the zh-TW branches.
120 lines
4.4 KiB
Go
120 lines
4.4 KiB
Go
package gui
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// The tray menu is in the page's language: the setting, or the system's
|
|
// when it follows the system (#301).
|
|
func TestTrayMenuLabels(t *testing.T) {
|
|
zhSys := func() string { return "zh-Hans-CN" }
|
|
enSys := func() string { return "en-US" }
|
|
for _, c := range []struct {
|
|
pref string
|
|
sys func() string
|
|
want string
|
|
}{
|
|
{"zh", enSys, "zh"},
|
|
{"en", zhSys, "en"},
|
|
{"system", zhSys, "zh"},
|
|
{"system", enSys, "en"},
|
|
{"", func() string { return "zh_CN.UTF-8" }, "zh"},
|
|
{"system", func() string { return "" }, "en"},
|
|
{"ja", enSys, "ja"},
|
|
{"system", func() string { return "ja-JP" }, "ja"},
|
|
{"", func() string { return "ja_JP.UTF-8" }, "ja"},
|
|
{"de", enSys, "de"},
|
|
{"system", func() string { return "de-DE" }, "de"},
|
|
{"", func() string { return "de_AT.UTF-8" }, "de"},
|
|
{"zh-TW", enSys, "zh-TW"},
|
|
{"system", func() string { return "zh-Hant-TW" }, "zh-TW"},
|
|
{"system", func() string { return "zh-TW" }, "zh-TW"},
|
|
{"system", func() string { return "zh-HK" }, "zh-TW"},
|
|
{"system", func() string { return "zh-Hant" }, "zh-TW"},
|
|
{"", func() string { return "zh_TW.UTF-8" }, "zh-TW"},
|
|
{"", func() string { return "zh_HK" }, "zh-TW"},
|
|
{"system", func() string { return "zh-Hans-HK" }, "zh"},
|
|
{"system", func() string { return "zh-SG" }, "zh"},
|
|
} {
|
|
if got := trayLang(c.pref, c.sys); got != c.want {
|
|
t.Errorf("trayLang(%q, %s) = %s, want %s", c.pref, c.sys(), got, c.want)
|
|
}
|
|
}
|
|
de := trayMenuLabels("de", "0.1.500", "0.1.501")
|
|
if de != (trayLabels{"magpie öffnen", "Version 0.1.500", "Zum Aktualisieren auf 0.1.501 neu starten", "magpie beenden"}) {
|
|
t.Errorf("de: %+v", de)
|
|
}
|
|
for lang, want := range map[string]string{"de": "en", "en": "en", "zh": "zh", "zh-TW": "zh"} {
|
|
if got := notesLang(lang); got != want {
|
|
t.Errorf("notesLang(%q) = %q, want %q", lang, got, want)
|
|
}
|
|
}
|
|
zh := trayMenuLabels("zh", "0.1.500", "")
|
|
if zh != (trayLabels{"打开 magpie", "版本 0.1.500", "重启以更新", "退出 magpie"}) {
|
|
t.Errorf("zh: %+v", zh)
|
|
}
|
|
if tw := trayMenuLabels("zh-TW", "0.1.500", "0.1.501"); tw != (trayLabels{"開啟 magpie", "版本 0.1.500", "重新啟動以更新到 0.1.501", "結束 magpie"}) {
|
|
t.Errorf("zh-TW: %+v", tw)
|
|
}
|
|
if ja := trayMenuLabels("ja", "0.1.500", ""); ja != (trayLabels{"magpie を開く", "バージョン 0.1.500", "再起動してアップデート", "magpie を終了"}) {
|
|
t.Errorf("ja: %+v", ja)
|
|
}
|
|
if l := trayMenuLabels("zh", "0.1.500", "0.1.501"); l.restart != "重启以更新到 0.1.501" {
|
|
t.Errorf("zh restart: %q", l.restart)
|
|
}
|
|
en := trayMenuLabels("en", "0.1.500", "0.1.501")
|
|
if en != (trayLabels{"Open magpie", "Version 0.1.500", "Restart to Update to 0.1.501", "Quit magpie"}) {
|
|
t.Errorf("en: %+v", en)
|
|
}
|
|
env := map[string]string{"LC_ALL": "C", "LANG": "zh_CN.UTF-8"}
|
|
if got := envLang(func(k string) string { return env[k] }); got != "zh_CN.UTF-8" {
|
|
t.Errorf("envLang skips C: %q", got)
|
|
}
|
|
if got := firstAppleLang("(\n \"zh-Hans-CN\",\n \"en-US\"\n)\n"); got != "zh-Hans-CN" {
|
|
t.Errorf("firstAppleLang: %q", got)
|
|
}
|
|
if got := firstAppleLang("(\n en,\n \"zh-Hans\"\n)\n"); got != "en" {
|
|
t.Errorf("firstAppleLang unquoted: %q", got)
|
|
}
|
|
}
|
|
|
|
// A language changed on the Settings page relabels the tray menu; a save
|
|
// that leaves it as it was doesn't.
|
|
func TestSettingsLangRelabelsTray(t *testing.T) {
|
|
h := t.TempDir()
|
|
t.Setenv("HOME", h)
|
|
t.Setenv("USERPROFILE", h)
|
|
t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config"))
|
|
t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache"))
|
|
if err := settings.Save(settings.Settings{Lang: "en"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
calls := 0
|
|
onLang = func() { calls++ }
|
|
t.Cleanup(func() { onLang = nil })
|
|
post := func(body string) {
|
|
rec := httptest.NewRecorder()
|
|
Handler(nil, nil).ServeHTTP(rec, httptest.NewRequest("POST", "/api/settings", strings.NewReader(body)))
|
|
if rec.Code != http.StatusOK {
|
|
t.Fatalf("%d %s", rec.Code, rec.Body)
|
|
}
|
|
}
|
|
post(`{"theme":"dark","lang":"en"}`)
|
|
if calls != 0 {
|
|
t.Fatalf("relabelled %d times with the language unchanged", calls)
|
|
}
|
|
post(`{"theme":"dark","lang":"zh"}`)
|
|
if calls != 1 {
|
|
t.Fatalf("relabelled %d times after en → zh, want 1", calls)
|
|
}
|
|
if l := trayMenuLabels(trayLang(settings.Load().Lang, systemLang), "1", ""); l.quit != "退出 magpie" {
|
|
t.Fatalf("after the change the menu reads %+v", l)
|
|
}
|
|
}
|