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
+17 -2
View File
@@ -408,8 +408,23 @@ The Docker image rebuilds the front end from source.
Handlers never contain user-facing text. They call `i18n.Bundle` with a
message ID. `HTML` escapes arguments for Telegram's HTML parse mode, `T`
returns plain text for buttons and callback answers. Sizes, durations and
percentages are formatted per locale. Callback data contains IDs only.
returns plain text for buttons and callback answers. Sizes, numbers,
durations, percentages and dates are formatted per locale. Callback data
contains IDs only.
Which language a message is in:
| Where | Language |
| --- | --- |
| Private chat, Mini App | the user's `/language` choice, else their Telegram language, else English |
| Group | the group's `/grouplang`, else the requester's language |
| Invoice memo, receipts | the language of the person who bought |
| Command menu | Telegram picks it by the app's language; a user or group with its own choice gets a chat menu in that language |
The fallback chain for one message is the exact tag, its base language,
then English, so a partial regional catalog (es-PY) only needs the lines
that differ. `locales/catalog_test.go` keeps the catalogs and the code in
step; see [TRANSLATING.md](TRANSLATING.md).
## Secrets
+115
View File
@@ -655,3 +655,118 @@ Checked against https://core.telegram.org/bots/webapps on 2026-11-18.
retry's file, and the job failed with an internal error. It showed up as
a rare test failure on a busy machine. Every attempt now has its own
directory, and a test holds the two slots in exactly that order.
## Phase 7
### Verified Bot API facts
Checked against https://core.telegram.org/bots/api (Bot API 10.4) on
2026-11-18, and against telego v1.13.0.
- `setMyCommands` takes at most 100 commands, a scope, and a two-letter
ISO 639-1 `language_code`. Without a code the list applies to users
whose language has no list of its own. A command is 1 to 32 lowercase
letters, digits or underscores; a description 1 to 256 characters.
- Telegram picks the menu in this order: chat scope with the user's
language, chat scope, then all private chats (or, in groups, chat
administrators, chat, all chat administrators, all group chats), then
default, each with and then without the language.
- `setMyName` (0 to 64 characters), `setMyDescription` (0 to 512, shown
in an empty chat) and `setMyShortDescription` (0 to 120, shown on the
profile and when the bot is shared) take the same `language_code`.
- `deleteMyCommands` removes the list of a scope and language.
### Languages
- English is the source and the fallback. Spanish and Dutch ship
complete. A user gets their Telegram language when a catalog matches
it, regional variants included (es-PY uses Spanish), and English
otherwise. `/language` (or the Mini App) overrides that per user;
`/grouplang` per group.
- Spanish: neutral Latin American with "tú". Paraguay speaks "vos", but
"tú" is what written Spanish across the region expects and is read
without friction in Paraguay; the vocabulary avoids words that sound
odd there. No opening `¿` or `¡`, as asked; a test enforces it.
- Dutch: informal "je".
- Owner texts are translated too. Owners pick their language like anyone.
- Command names, their arguments (`/spending admins`) and product IDs
stay English in every language. The bot parses them.
- The invoice memo, which wallets show, is the brand name plus the
product in the payer's language.
### Menus and profile
- At startup the core publishes three menus in every language: private
chats (download, account and preference commands), group members
(download commands, the group wallet and pass) and group admins (the
same plus the settings commands). Owner commands are never listed.
`/app` is listed only when the Mini App is on.
- The source language is published without a language code, so it is
also the menu for languages without a catalog.
- Telegram chooses menus by the language of the user's app, not by the
bot's setting. So when a user picks a language in the bot, the core
sets a menu for that private chat alone; "follow my Telegram language"
deletes it. `/grouplang` does the same for the group's member and
admin menus. These calls are limited to six per minute per chat.
- Chat menus are not rewritten when a catalog changes. They refresh the
next time that user or group changes language. The general menus are
rewritten at every start and on `/reload i18n`.
- The bot's name, description and short description are set per
language from `profile.*`, but only when the text changed since the
last time it went through, because Telegram limits these calls
hard. `TELEGRAM_SET_PROFILE=false` leaves what was set in @BotFather.
A change made in @BotFather is overwritten only when the catalog text
changes.
### Formatting
- Numbers use the language's grouping and decimal marks (Go's
`golang.org/x/text`, and `Intl` in the Mini App): "1.000 sats",
"10,0 MB" in Spanish and Dutch.
- Dates are written from the catalog (`format.date`, `format.datetime`,
`format.months`): "18 nov 2026, 12:05 UTC". Always UTC, and labeled:
the bot does not know the reader's time zone. Limits reset at midnight
UTC, which the texts say.
- Durations in words use the plural rules of the language ("5 minutos").
Media lengths are written as 4:05 everywhere.
### Completeness check
- `locales/catalog_test.go` is the check CI runs (`make i18n-check`).
For every catalog it fails on: a message missing or extra compared with
the source, a plural that is plain elsewhere or lacks `one`, a changed
set of placeholders, HTML tags or commands, broken braces, empty
texts, stray spaces, em dashes, inverted marks in Spanish, menu and
profile texts over Telegram's limits, button labels over 40
characters, a month list that is not twelve long, and a duplicate
language name. It also flags longer texts identical to English, except
where they are meant to be (the brand name in the invoice memo).
- It also reads the code. Every message of the source must be used,
either by its full ID or by a prefix or suffix the code builds IDs from
(`"error." + code`, `name + ".list"`), and every ID-shaped string in the
code whose table exists must be in the catalog. Tests are not counted.
`web/miniapp/embed_test.go` does the same for the Mini App.
- `.github/workflows/ci.yml` runs this, the whole suite with the race
detector, the suite on Postgres, and the Mini App build and browser
test. It was written for GitHub Actions and has not run there yet;
every step in it was run here by hand.
### Pseudo-locale
- `I18N_PSEUDO=true` makes `en-XA` from the English catalog at load time:
accented letters, brackets, a third longer, with placeholders, tags,
entities, commands, links and mentions kept. Plurals and dates keep
working.
- It is hidden from users and offered to owners only, in `/language`,
`/grouplang` and the Mini App. It is never published to Telegram
(not a two-letter code).
### Fixed on the way
- The test helper that sets up a waiting download picked the first "In
the queue" status edit after the second user's press, from any chat.
Under load a late edit of the first user's status could match, and the
test then pressed the wrong button. It now matches the second user's
chat only. This is the likely cause of the one Postgres failure of
`TestSkipTheQueueWithInvoice` reported in Phase 4, which uses the same
helper. The bot itself was right in both cases.
+14
View File
@@ -174,6 +174,20 @@ opened again.
If step 3 is skipped, the button in private chats still works. Only the
`?startapp` links from groups and the profile button need it.
## Languages, menus and the bot's profile
At every start the core publishes its command menus in every language it
has a catalog for, and sets the bot's name, description and short
description per language from the catalogs. The profile texts are only
sent again when they change, because Telegram rate limits those calls.
- To keep a name or description you set in @BotFather, set
`TELEGRAM_SET_PROFILE=false`. Or edit `profile.*` in the catalogs.
- To change any text, edit `locales/*.toml` and rebuild, or run with
`LOCALES_DIR` pointing at a copy of `locales/` and send `/reload i18n`.
- `I18N_PSEUDO=true` adds a test language for owners, see
[TRANSLATING.md](TRANSLATING.md).
## Health and logs
- `GET /healthz` on the core answers 200 while the database is reachable.
+88
View File
@@ -0,0 +1,88 @@
# Translating the bot
Every text the bot and the Mini App show lives in one catalog per language
in `locales/`. English (`en.toml`) is the source. Spanish (`es.toml`) and
Dutch (`nl.toml`) ship complete.
## How a catalog looks
```toml
[status]
queued = "In the queue. Position {{.Position}}, about {{.Wait}}."
[unit.minutes]
one = "{{.Count}} minute"
other = "{{.Count}} minutes"
```
- A table plus a key is a message ID: `status.queued`.
- `{{.Name}}` is filled in by the bot. Keep it exactly as it is; you may
move it within the sentence.
- A table whose keys are `one`, `other` (and for some languages `few`,
`many`, ...) is a plural. The bot picks the form from `Count` using the
CLDR rules of the language. Give at least `one` and `other`.
- Most chat texts are Telegram HTML. Keep `<b>`, `<i>`, `<code>` and the
line breaks. Do not add new tags.
- Commands (`/dl`, `/help`) and the arguments shown in `<code>` examples
(`/spending admins`) are not translated: the bot only understands them
as they are.
- The `[app]` table is the Mini App. It is plain text, no HTML.
- `[menu]` is Telegram's command menu (up to 256 characters each, one
line). `[profile]` is the bot's name (64), the description shown in an
empty chat (512) and the short description on the profile (120).
- `[format]` says how dates are written: twelve short month names, and
the order of day, month, year and time.
- Do not use the words `id`, `description`, `hash`, `leftdelim`,
`rightdelim`, `zero`, `one`, `two`, `few`, `many` or `other` as a key
name. The library reserves them.
- No em dashes anywhere.
## Adding a language
1. Copy `en.toml` to `<code>.toml`, where the code is a two-letter ISO
639-1 language code (`pt.toml`, `de.toml`). Telegram publishes menus
and profile texts per two-letter code only. A regional catalog
(`pt-BR.toml`) works for messages, but shares the menu of its base
language.
2. Translate every value. Change `language.name` to the language's own
name for itself ("Português").
3. Run the checks:
```sh
make i18n-check
```
They fail on a missing or extra message, a changed placeholder, tag or
command, a missing plural form, a text over Telegram's length limit, an
em dash, and on longer texts left identical to English.
4. Restart the core. The new language shows up in `/language`, in the
Mini App, in the menus and on the bot's profile. Users whose Telegram
is set to that language get it without doing anything.
Without a restart: run the core with `LOCALES_DIR=/path/to/locales` and
send `/reload i18n` as an owner. A catalog that fails to load leaves the
old ones in use and says why.
A right-to-left language (Arabic, Hebrew, Persian, Urdu) needs nothing
extra. The Mini App mirrors its layout by itself.
## Checking a translation in place
`I18N_PSEUDO=true` adds a pseudo-locale, `en-XA`: English with every
letter accented and every text in brackets, a third longer. Owners can
pick it with `/language` or in the Mini App. Text that still reads as
plain English while it is on did not come from the catalog; text cut off
before its closing bracket has too little room.
## The Spanish catalog
Neutral Latin American Spanish, with words that read naturally in
Paraguay: "tú" forms, "enlace", "descargar" and "bajar", "billetera",
"fila" for the queue, "factura" for a Lightning invoice. Questions and
exclamations are written without the opening `¿` and `¡`; the checks
enforce that.
## The Dutch catalog
Informal ("je"), as most Dutch apps are. "Pas", "tegoed", "factuur",
"wachtrij"; "wallet" is left as it is, as Dutch Lightning users say it.