Table of Contents
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:
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 (
msgmergekeeps 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.
export global Strings {
pure public function connection-lost(reason: string) -> string {
return @tr("Connection lost: {}", reason);
}
}
let text = window.global::<Strings>().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/<lang>/LC_MESSAGES/<crate>.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).
# 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). 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:
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-<lang>/. - Desktop file and AppStream metainfo: translated with
itstool/msgfmt --desktop/msgfmt --xmlfrom.pofiles 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/) withmsgenfrom the template, replace the texts with longer accented versions, and select it with the language setting (orLANG=eo.UTF-8on 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.
Mirrored from docs/i18n.md at a3964f6 by .claude/wiki-sync.js. Edit the file in the repository, not this page: the next sync overwrites it.