Add i18n scaffolding and mark strings for translation #3
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
Terminalko is a GTK4/libadwaita application in Rust. User-visible text comes from
two places:
ui/*.blp) — already marked with_("…"):95 strings across
window.blp(17),preferences.blp(40),session_editor.blp(35),page.blp(3).crates/terminalko/src/*.rs:menu labels built in code (
window.rs::session_menu,colour_menu, the Newmenu in
rebuild_new_menu, the terminal context menu interminal.rs::context_menu_model), dialog headings and bodies (prompt,confirm_delete,confirm_paste), the reattach marker(
terminal.rs::reattach_marker), page notices, and the fallbacks"Untitled"and
"Terminalko".There is currently no
po/directory, no gettext dependency and no extractionstep, so none of it is translatable.
Why this is an issue rather than a small change
Two separate pieces of work:
po/directory withPOTFILES.inandLINGUAS, meson'si18nmodule wired up,gettext-rs(or glib's gettext bindings) initialisedin
mainwith the right text domain andLOCALEDIR.mechanical but touches most of the GUI crate, which is why it is not being
done as part of another change.
There is also a build wrinkle worth knowing before starting:
xgettextdoesnot understand
.blp. Options, in rough order of preference:xgettextwith--language=C --keyword=_ --keyword=C_:1c,2over the.blpfiles, which works because blueprint's_("…")is C-shaped;.uifiles (they land inOUT_DIR/ui— seecrates/terminalko/build.rs) and let gettext's GtkBuilder ITS rules handlethem, which means the extraction step depends on a build having happened.
Pick one and write down why in the spec.
Goal
Every user-visible string is extractable and translated at runtime, with the
English output unchanged when no translation exists.
Suggested approach
gettext-rstocrates/terminalko, initialise the text domain inmain.rsbefore the application is built, using theLOCALEDIRthat mesonpasses (
build.rsalready forwardsTK_APP_ID,TK_VERSIONandTK_PKGDATADIRthis way — addTK_LOCALEDIRalongside them).gettexthelper (or use the crate's macro) and wrap the 49 literals.Keep
glib::g_warning!and log messages unwrapped: they are fordevelopers, not users.
po/POTFILES.in,po/LINGUAS(may start empty),po/meson.buildwithi18n.gettext(gettext_package, preset: 'glib'), andsubdir('po')in theroot
meson.build. The gettext package name should be the binary name, asconf/build.rsalready use elsewhere.build-aux/ci.shwith a check that the template is up to date — anunextracted new string should fail CI rather than be noticed a release later.
(
i18n.merge_filefordata/*.desktop.inand*.metainfo.xml.in, which arecurrently substituted with
configure_file).Acceptance criteria
meson compile -C build terminalko-pot(or the equivalent target) produces a.potcontaining both the blueprint and the Rust strings; spot-check thatstrings from
window.rs::session_menuandpreferences.blpare both present.LANG=Cthe application looks exactly as it does today.xxlocale with a couple of strings)visibly changes the UI when run with that locale, proving the runtime path
works end to end.
meson installinstalls the compiled catalogues under<prefix>/share/locale../build-aux/ci.shand./build-aux/smoke.shpass.docs/spec/i18n.mddescribing the extraction route chosen and why.Notes
terminalkoctlprint: those aredeveloper- and script-facing, and
terminalkoctloutput is parsed by tests.ngettextwhere a count is involved — the paste guard's "Theclipboard holds N lines" in
window.rs::confirm_pasteis the one that needs ittoday.