Phase 7: languages

- Complete Spanish (neutral Latin American, Paraguay friendly, no
  inverted marks) and Dutch catalogs, including the Mini App and owner texts
- Command menus per language in three scopes (private, group members,
  group admins); per-chat menus follow a user's /language and a group's
  /grouplang, from chat and from the Mini App
- Bot name, description and short description per language, sent only
  when the catalog text changes (TELEGRAM_SET_PROFILE)
- Dates from the catalog, numbers, sizes and durations per locale
- Pseudo-locale en-XA generated from English (I18N_PSEUDO), owners only
- Catalog checks: completeness, placeholders, tags, commands, plurals,
  Telegram length limits, untranslated text, unused and missing IDs
- CI workflow; make i18n-check; docs/TRANSLATING.md
- Test fix: the queued-download helper could match another chat's status

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Michilis
2026-11-18 17:42:31 +00:00
co-authored by Claude Opus 5.5
parent 4f11f939a0
commit f1f9c6156c
27 changed files with 3217 additions and 71 deletions
+93
View File
@@ -200,3 +200,96 @@ func TestDir(t *testing.T) {
}
}
}
func TestPseudoLocale(t *testing.T) {
b, err := i18n.Load(locales.FS, nil, i18n.WithPseudo())
if err != nil {
t.Fatal(err)
}
if !b.Hidden(i18n.Pseudo) {
t.Fatal("the pseudo-locale must be hidden from users")
}
found := false
for _, l := range b.Langs() {
found = found || l == i18n.Pseudo
}
if !found {
t.Fatalf("languages = %v, want %s among them", b.Langs(), i18n.Pseudo)
}
got := b.HTML(i18n.Pseudo, "start.private", i18n.Args{"Name": "Ana"})
if !strings.Contains(got, "<b>") || !strings.Contains(got, "Ana") || !strings.Contains(got, "/help") ||
strings.Contains(got, "welcome") || !strings.Contains(got, "[") {
t.Fatalf("pseudo start = %q", got)
}
// Plurals keep working.
if one, many := b.T(i18n.Pseudo, "unit.sats", i18n.Args{"Count": 1, "N": "1"}), b.T(i18n.Pseudo, "unit.sats", i18n.Args{"Count": 5, "N": "5"}); one == many || !strings.Contains(many, "5") {
t.Fatalf("pseudo plurals = %q, %q", one, many)
}
if d := b.DateTime(i18n.Pseudo, time.Date(2026, 3, 4, 5, 6, 0, 0, time.UTC)); !strings.Contains(d, "Ṁáŕ") || !strings.Contains(d, "05:06") {
t.Fatalf("pseudo date = %q", d)
}
// The Mini App gets it too.
if s, _ := b.Section(i18n.Pseudo, "app")["tab.home"].(string); !strings.HasPrefix(s, "[Ĥöḿé") {
t.Fatalf("pseudo app text = %q", s)
}
// Without the option it does not exist.
plain := load(t)
for _, l := range plain.Langs() {
if l == i18n.Pseudo {
t.Fatal("the pseudo-locale is loaded without being asked for")
}
}
}
func TestPseudolocalizeKeepsMarkup(t *testing.T) {
for in, want := range map[string]string{
"Hi {{.Name}}": "[Ĥî {{.Name}} ~]",
"<b>Paid</b> &amp; done": "[<b>Þáîð</b> &amp; ðöñé ~~~]",
"Try /help or https://x.y/a?b=c": "[Ţŕý /help öŕ https://x.y/a?b=c ~~]",
"\nTwo\nlines\n": "\n[Ţŵö\nļîñéš ~~~]\n",
} {
if got := i18n.Pseudolocalize(in); got != want {
t.Errorf("Pseudolocalize(%q) = %q, want %q", in, got, want)
}
}
}
func TestDatesFollowTheCatalog(t *testing.T) {
b := load(t)
at := time.Date(2026, 11, 18, 9, 5, 0, 0, time.FixedZone("PYT", -3*3600))
if got := b.DateTime("en", at); got != "18 Nov 2026, 12:05 UTC" {
t.Errorf("en = %q", got)
}
if got := b.Date("en", at); got != "18 Nov 2026" {
t.Errorf("en date = %q", got)
}
for lang, want := range map[string]string{"es": "18 nov 2026, 12:05 UTC", "es-PY": "18 nov 2026, 12:05 UTC", "nl": "18 nov 2026, 12:05 UTC"} {
if got := b.DateTime(lang, at); got != want {
t.Errorf("%s = %q, want %q", lang, got, want)
}
}
if got := b.DateTime("nl", time.Date(2026, 3, 1, 0, 0, 0, 0, time.UTC)); got != "1 mrt 2026, 00:00 UTC" {
t.Errorf("nl March = %q", got)
}
}
func TestNumbersAndUnitsPerLanguage(t *testing.T) {
b := load(t)
cases := []struct{ lang, got, want string }{
{"en", b.Sats("en", 10000), "10,000 sats"},
{"es", b.Sats("es", 10000), "10.000 sats"},
{"nl", b.Sats("nl", 10000), "10.000 sats"},
{"es", b.Sats("es", 1), "1 sat"},
{"es", b.Size("es", 5<<20), "5,0 MB"},
{"nl", b.Size("nl", 3<<29), "1,50 GB"},
{"es", b.Span("es", 5*time.Minute), "5 minutos"},
{"nl", b.Span("nl", time.Minute), "1 minuut"},
{"nl", b.Span("nl", 3*time.Hour), "3 uur"},
{"es-PY", b.T("es-PY", "status.done", nil), "Listo. Que lo disfrutes."},
}
for _, c := range cases {
if c.got != c.want {
t.Errorf("%s: %q, want %q", c.lang, c.got, c.want)
}
}
}