# Translations The UI uses Slint's gettext-based translation markers: strings in `.slint` files are marked with `@tr(...)`, extracted into a `.pot` template, translated in `.po` files, and can be **compiled into the binary** (Slint's bundled translations). The repository currently has a `.pot` template but no `.po` translations; bundled translations are not enabled yet. Nothing needs to be loaded at runtime, so there is no dependency on GNU gettext (LGPL) and it works the same on Linux, Windows and Android. ## Marking strings In `.slint` files every user-visible string goes through `@tr`: ```slint Button { text: @tr("Connect"); } Text { text: @tr("Connected to {}", server-name); } // arguments: {} or {0} {1} Text { text: @tr("{n} user online" | "{n} users online" % count); } // plurals Text { text: @tr("menu" => "Quit"); } // explicit context ``` - Whole sentences with placeholders, never concatenated fragments: word order differs between languages. Use `{0}`, `{1}` when there are several arguments, so translators can reorder them. - Plurals always with the `|` / `%` form, even if English only needs two forms; other languages have more. - Not translated: nicknames, channel and server names, chat text, protocol identifiers, the product name, log messages. - By default the context of a string is the name of the component it is in, so the same English word can be translated differently in different places. Renaming a component therefore invalidates its translations until they are merged again (`msgmerge` keeps them as fuzzy). Strings produced in Rust (error messages, notification texts, status lines) cannot use `@tr`. Keep the wording in Slint: an exported global with pure functions that the Rust code calls, e.g. ```slint export global Strings { pure public function connection-lost(reason: string) -> string { return @tr("Connection lost: {}", reason); } } ``` ```rust let text = window.global::().invoke_connection_lost(reason.into()); ``` Errors from lower layers (protocol, IO) are shown as details after a translated sentence; they stay in English. ## Files ``` crates/voelin-ui/lang/ voelin-ui.pot template, generated de/LC_MESSAGES/voelin-ui.po one directory per language (gettext locale name) pt_BR/LC_MESSAGES/voelin-ui.po ``` The file name is the translation domain, which is the crate name (`voelin-ui`); Slint's build looks for `lang//LC_MESSAGES/.po`. ## Workflow Tools (developer machines only): `cargo install slint-tr-extractor`, and GNU gettext for `msgmerge` / `msginit` (`gettext` package; on Windows from MSYS2 or Git for Windows' bundled tools). ```sh # 1. Extract the template after changing strings mkdir -p crates/voelin-ui/lang rg --files crates/voelin-ui/ui -g '*.slint' | sort | \ xargs slint-tr-extractor --package-name voelin-ui -o crates/voelin-ui/lang/voelin-ui.pot # 2. Update every translation (new strings empty, changed ones fuzzy) for po in crates/voelin-ui/lang/*/LC_MESSAGES/voelin-ui.po; do msgmerge --update --backup=none "$po" crates/voelin-ui/lang/voelin-ui.pot done # 3. Start a new language mkdir -p crates/voelin-ui/lang/de/LC_MESSAGES msginit --no-translator --locale=de --input=crates/voelin-ui/lang/voelin-ui.pot \ --output-file=crates/voelin-ui/lang/de/LC_MESSAGES/voelin-ui.po ``` Translators edit the `.po` files (Poedit, Lokalize, or a hosted service such as Weblate pointed at `crates/voelin-ui/lang`). Fuzzy and untranslated entries fall back to English. Run the extraction when strings change and before each release (string freeze, see [release.md](release.md)). The template carries a creation date and source line numbers, so CI does not compare it exactly; a stale template only means new strings are not translatable yet. ## Bundling and language selection Once the first `.po` translation exists, configure `crates/voelin-ui/build.rs` to compile translations into the binary: ```rust slint_build::compile_with_config( "ui/app.slint", slint_build::CompilerConfiguration::new() .with_style("fluent-dark".into()) .with_bundled_translations("lang"), ) ``` slint-build tracks the `.po` files, so edits rebuild. It fails ("No translations found") while `lang/` has no `.po` file yet, so enable it together with the first language. At startup Slint picks the translation matching the system locale (exact match such as `pt_BR` first, then the language `pt`), English otherwise. A language setting in the app (stored in the settings, "System" by default) calls `slint::select_bundled_translation("de")` after the window has been created; `""` or `"en"` selects English. Changing it takes effect immediately for all `@tr` strings. The desktop app (voelin-ui) and the Android app share the `.slint` files and therefore the translations. Texts outside Slint need their own mechanism: - Android system texts (foreground service notification, permission rationale): Android string resources in `android/app/src/main/res/values-/`. - Desktop file and AppStream metainfo: translated with `itstool` / `msgfmt --desktop` / `msgfmt --xml` from `.po` files when there are translations for the app itself. ## Checks - A pseudo-translation catches unmarked strings and truncation: create a test language (e.g. `lang/eo/`) with `msgen` from the template, replace the texts with longer accented versions, and select it with the language setting (or `LANG=eo.UTF-8` on Linux). - Test at least one language with longer words (German) and one with a different script (Russian) on every screen before a release (manual matrix row GE7). - Dates and numbers are formatted in Rust; use unambiguous formats (ISO dates, 24-hour times) until there is locale-aware formatting.