SLINTLU / I18N

Translations

Translate a shell with gettext catalogues and switch languages at runtime.

Write user-visible texts with Slint’s @tr():

Text { text: @tr("Volume"); }
Text { text: @tr("{n} window" | "{n} windows" % Workspaces.windows.length); }

Extract them with Slint’s extractor and translate the .po files with any gettext tool (Poedit, Lokalize, Weblate …):

cargo install slint-tr-extractor
find ~/.config/slintlu -name '*.slint' | xargs slint-tr-extractor --no-default-translation-context -o ~/.config/slintlu/i18n/messages.pot
msginit -i ~/.config/slintlu/i18n/messages.pot -l de -o ~/.config/slintlu/i18n/de.po

SlintLu compiles shells without a default translation context, so a text has one translation wherever it appears (hence --no-default-translation-context); use @tr("context" => "text") where the same English text needs different translations.

Put the translations next to the shell, either as i18n/<language>.po or as i18n/<language>/LC_MESSAGES/<anything>.po. SlintLu compiles them itself on every (re)load — no msgfmt needed — and picks the language from LANGUAGE, LC_ALL, LC_MESSAGES or LANG.

The I18n global lists the available languages and switches at runtime:

import { I18n } from "@slintlu";

for language in I18n.languages: Button {
    text: language;
    clicked => { I18n.set-language(language); }
}
slintlu msg call I18n.set-language zh_TW

Runtime switching uses gettext’s LANGUAGE variable, which glibc ignores while the process runs in the C / POSIX locale; make sure LANG names a real locale.