Files
openchamber-android-native/third_party/mygo/ui/locale_test.go
T
OpenChamber 6c0ee61750 feat: port the client to MyGo native UI (0.3.0)
Switch from Asuka to MyGo, keeping the API client and the feature set:

- servers: saved servers, passwordless and password login, proxy,
  self-signed certificates, per-server device tokens (Keystore), connect
  form, instance list sheet with switch/disconnect
- sessions: virtualized list, search, new session, rename/archive/delete,
  running indicator, event stream keeps it live
- chat: pushed window with system back bar, streaming Markdown via
  ui/markdown, reasoning and tool rows with image previews, footer menu
  (read aloud via a Kotlin TTS plugin, copy, fork), user message menu
  (copy, revert, fork), context usage ring and detail sheet, attachments
  (photos/files via the document picker), permissions
- release builds allow plain http:// LAN servers (Go's net/http dials
  directly, no cleartext manifest needed)
- a local fork of MyGo (third_party/mygo) lowers the Android host's
  minSdk to 24 (Android 7.0); Go 1.27.4 via mise

Version 0.3.0.
2026-11-18 13:22:59 +08:00

53 lines
1.7 KiB
Go

package ui
import (
"testing"
"time"
"github.com/egoist/mygo/i18n"
"github.com/egoist/mygo/internal/text"
)
// TestLang holds the language of text to the language the app shows,
// which an element's Lang overrides for its text and that of the elements
// inside it, and a span's for its runes.
func TestLang(t *testing.T) {
var plain, quote, inner, reset text.Params
var spans []text.Span
var locale string
var region i18n.Region
tt := coreNewTester(func(c *context) {
locale, region = c.Locale(), c.Region()
coreColumn(c).Children(func() {
plain = coreText(c, "直").textParams(0)
coreColumn(c).Lang("ja").Children(func() {
quote = coreText(c, "直").textParams(0)
inner = coreText(c, "直").Lang("zh-Hant").textParams(0)
reset = coreText(c, "直").Lang("").textParams(0)
})
rich := coreRichText(c, Span{Text: "直"}, Span{Text: "骨", Lang: "ja"})
spans = text.DecodeSpans(rich.textParams(0).Spans)
})
}, 200, 200)
if plain.Style.Lang != "" || locale != "" {
t.Errorf("a Tester shows %q, text in %q: want none", locale, plain.Style.Lang)
}
tt.SetLocale("zh-Hans")
tt.SetRegion(i18n.Region{Locale: "en-GB", FirstWeekday: time.Monday, HourCycle: 24})
if locale != "zh-Hans" || region.Locale != "en-GB" {
t.Errorf("the view sees %q %+v", locale, region)
}
for _, c := range []struct {
name string
p text.Params
want string
}{{"plain", plain, "zh-Hans"}, {"quote", quote, "ja"}, {"inner", inner, "zh-Hant"}, {"reset", reset, "ja"}} {
if c.p.Style.Lang != c.want {
t.Errorf("%s text is in %q, want %q", c.name, c.p.Style.Lang, c.want)
}
}
if len(spans) != 2 || spans[0].Lang != "" || spans[1].Lang != "ja" {
t.Errorf("the spans are %+v", spans)
}
}