This document describes how translated UI strings are produced, loaded at runtime, and maintained. It replaces the older split between a “plan” and a short overview.
- GNU gettext (
.pottemplate, per-localewriteragent.po, compiledwriteragent.mounderlocales/<lang>/LC_MESSAGES/). - Runtime loading in
plugin/framework/i18n.py:init_i18n()installs agettext.translationfor domainwriteragent; user code wraps strings with_(). - Locale source: LibreOffice’s UI locale from configuration path
/org.openoffice.Setup/L10N→ propertyooLocale(seeget_lo_locale()). Values likeen-USare normalized to gettext-styleen_US. If lookup fails, the code falls back toen_USso behavior stays predictable in tests or early init. - Missing strings:
fallback=Trueon the translation object means untranslated or absent catalogs show the Englishmsgid.
There is no separate “UI language” override in writeragent.json today: displayed language follows LibreOffice’s UI locale plus whichever .mo files are packaged for that locale.
String extraction and catalog updates are driven by scripts/extract_strings.py.
-
Python: User-visible literals should use
_('...')(or the same pattern with format strings). Afterinit_i18n(),_()delegates to gettext. -
XDL dialogs: English strings in
.xdlfiles are not read byxgettextdirectly.scripts/extract_xdl_strings.pygenerates a temporaryplugin/xdl_strings.pycontaining_()calls so those strings are picked up; that stub is removed after extraction. -
Input list & xgettext: Python files are collected depth-first and written to a temporary list file passed to
xgettextvia-f.--keyword=N_is passed on bothextract-stringsandrefresh-potpaths (extracts_andN_). Slash-command English ids are registered withN_("help"), …; translators map those msgids to a localized alias in each locale's catalog. At runtime_()resolves the display name and typed-alias matching for the active catalog only; a missing or identity translation keeps the English id. -
Module metadata:
scripts/merge_module_yaml_into_pot.pymerges translatable entries fromplugin/**/module.yaml(titles, labels, helpers,button_text, options) into the same POT, deduplicated bymsgid.button_textis the button caption (dlg:value→Label);translate_dialogalready calls_()on it, so a missing catalog entry stays English. Requirespoliband PyYAML. -
Dialogs at runtime:
translate_dialoginplugin/chatbot/dialogs.pywalks controls and applies translated text. Do not pass raw saved config values through_(): empty strings can pick up gettext header garbage. Config validation strips bogus gettext headers; seetests/framework/test_i18n.py.Combos rebuilt in Python after
translate_dialog(sidebar image aspect) must pass display strings through_("Square")-style literals. Storedimage_default_aspectstays the English label;canonical_aspect_labelmaps the visible text back before the image-tool enum. The chat role prefix is_("Assistant:")inappend_rich_text_with_span, not a bare literal. -
Monaco editor (pywebview): User-visible strings live in Python only —
plugin/scripting/editor_ui_strings.py.launch_monaco_editor()enriches every IPCloadmessage with a pre-translateduidict;editor.jsapplies it inapplyLoadMessage(). Add new shell strings in Python_(), runmake extract-strings, then read the key fromload.uiin JS. See scripting/monaco-editor-dev-plan.md § Localization.
| Target | Role |
|---|---|
make extract-strings |
Full pipeline via scripts/extract_strings.py: XDL stub → xgettext (-f, --keyword=N_) → YAML merge → delete stub → merge-translations on every writeragent.po. Use when sources change and you want POT and all POs updated. |
make refresh-pot |
scripts/extract_strings.py --pot-only: regenerates writeragent.pot only (with --keyword=N_) without merging into .po files. |
make preview-translations |
refresh-pot then scripts/translate_missing.py --preview (status table of completion vs POT). Used by normal make build. |
make merge-translations |
scripts/extract_strings.py --merge-only: for each writeragent.po, msgmerge --update from writeragent.pot, then msgattrib --no-obsolete so removed strings do not linger as obsolete entries. |
make compile-translations |
Compile every .po to .mo via scripts/compile_translations.py (polib.save_as_mofile; no GNU msgfmt / find). Required for LibreOffice and for unit tests that load catalogs. |
make compile-translations-core |
LibrePy only: build build/generated/librepy.pot from bundled sources (_() and N_() via ast, no GNU xgettext), filter each writeragent.po to those msgids, compile slim .mo with polib (no msgfmt) under build/generated/locales/ (part of make build-core). Windows CI does not have gettext on PATH (GHA 33780509372). |
make add-language LANG=xx |
Creates locales/xx/LC_MESSAGES/writeragent.po from the POT and compiles an initial .mo. |
Note: make build runs preview-translations (refresh POT + preview), not necessarily the full extract-strings + merge. Run make extract-strings when you add or change marked strings and need all locale files updated from the new template.
Release / AI assist: make release-build uses auto-translate (scripts/extract_strings.py --auto-translate), which regenerates strings with extract-strings, previews, then (if OPENROUTER_API_KEY is set) runs translate_missing.py --execute to fill gaps. Manual runs: make translate-missing or python scripts/translate_missing.py --execute.
Optional automation for translators:
- Compares each locale’s
writeragent.potowriteragent.potand finds missing, empty, or fuzzy entries. --previewprints the completion table (POT totals, pending, done, percentage) and exits; used bymake preview-translations/make build.- With
--execute, prints that same table at start unless--skip-initial-status, then fills gaps via the API. - Sends strings to an OpenAI-compatible chat API (default model
google/gemini-3.1-flash-lite-preview, default endpoint OpenRouter) in batches; usesOPENROUTER_API_KEYwhen available. - Preserves leading/trailing whitespace on strings by peeling it before the API call and re-applying it to results.
- Parses model JSON with
safe_json_loads(strict=Falseand repair fallbacks) so multiline UI strings (e.g. Calc Python editor errors with embedded newlines) do not fail batch fill with “invalid control character” from strictjson.loads.
Same script as gap fill; does not modify any .po or .mo file.
--review: sends every non-empty translation (including fuzzy) to the model for critique. You must pass--model <name>(no default on this path—use a different model than gap-fill if you want independent suggestions).--executestill defaults togoogle/gemini-3.1-flash-lite-previewwhen--modelis omitted.--output PATH: optional; default file name istranslation_review_<locale>.jsonortranslation_review_<l1>_<l2>_….jsonwith sorted locale directory names when multiple locales are reviewed.- While running, each finished batch prints one line per string to stdout (dense: batch size in = lines out). Acceptable rows show the fixed phrase
No Errors; onlysuggestrows include current text, suggestion, and English reasoning. - The model returns a JSON array of exactly that many objects (
action:okorsuggest). Forok,reasoning_enmust be exactlyNo Errors(the script also normalizes verbose “keep” replies to that literal). - Report JSON includes
generated_at,model,endpoint,locales,reviewed_string_count(how many strings were reviewed), andsuggestions: only rows withactionsuggestorerror(nook/No Errorsrows in the file).
This is a productivity aid, not a substitute for human review of tone and terminology.
LibreOffice supports localized properties with <value xml:lang="...">. The project’s .xcu files use this shape but mostly only define en-US / en today.
WriterAgent menubar titles are not left to that en-US string. get_menu_text returns a _("…") literal and addStatusListener pushes it with FeatureStateEvent.State. A command missing from that map (or returned as a raw English literal) keeps the Addons.xcu English title even when the .po has a msgstr. Hamburger items call _() at popup build time and do not use this map.
A practical policy (from earlier design notes, still relevant):
- Keep system/tool instructions in English when that improves model comprehension (especially for smaller or local models).
- Add or keep a clear instruction that conversational replies to the user should match the user’s language when that differs from the prompt language.
- Users can still override behavior with additional instructions in Settings.
This is separate from gettext: gettext handles fixed UI strings; the model handles free-form chat language.
These are useful directions, not commitments:
- Pluralization: Expose
ngettext(and possiblynpgettext) fromi18n.pyanywhere English uses “one vs many” or per-locale plural rules. - Message context: Use
pgettext/msgctxtwhere the same English word must translate differently (e.g. “Table” in Writer vs Calc). - RTL locales: Arabic, Hebrew, etc. may need layout or UNO adjustments beyond string translation; test dialogs and sidebar with RTL UI.
- Automated checks: Optional tests or lint rules that flag unwrapped user strings in high-traffic UI modules; CI jobs that run
extract-stringsand fail on accidental POT drift if desired. - Translation platform: Weblate, Crowdin, or Transifex if community scale grows; export
writeragent.potas the handoff artifact. - String freeze: Before a release aimed at translators, freeze
msgidchurn to reduce merge noise. - Coverage reporting: Extend or reuse the logic in
translate_missing.py’s status output to publish a simple per-language table in docs or CI logs.
For day-to-day contributor steps (extract, merge, Poedit, compile), see locales/README.md.
[feature M many]Exposengettextandnpgettextfromi18n.pyso one-versus-many strings follow per-locale plural rules. (§ Future considerations)[fidelity S many]Usepgettextmessage contexts where the same English word must translate differently, such as "Table" in Writer versus Calc. (§ Future considerations)[fidelity M few]Test and adjust dialogs and the sidebar for right-to-left locales such as Arabic and Hebrew. (§ Future considerations)[eng S few]Add a test or lint rule that flags unwrapped user-facing strings in high-traffic UI modules, and a CI check for accidental POT drift. (§ Future considerations)[eng S few]Publish a per-language translation coverage table in docs or CI logs by reusing the status logic intranslate_missing.py. (§ Future considerations)[idea M few]Move translation to a hosted platform such as Weblate, Crowdin or Transifex, withwriteragent.potas the handoff, if the community grows. (§ Future considerations)[idea S few]Freezemsgidchurn before a translator-facing release to reduce merge noise. (§ Future considerations)