Skip to content

Translations

jejellyroll-fr edited this page Nov 6, 2026 · 3 revisions

Translations

fpdb ships 14 locale catalogues. Choose one from View → Language; the choice is saved and takes effect when fpdb next starts.

The menu shows how much of each language is translated. French is complete; the others are partly translated, and the untranslated parts show in English. This is where help is most welcome.

View → Language, with each catalogue's completion

ca_ES Catalan de_DE German es_ES Spanish fr_FR French
hu_HU Hungarian it_IT Italian ja_JP Japanese lt_LT Lithuanian
nl_NL Dutch pl_PL Polish pt_BR Portuguese (Brazil) ro_RO Romanian
ru_RU Russian zh_CN Chinese (Simplified)

Two entries in the Language menu are not locales:

  • system — follow the operating system's language. The default.
  • en — the source strings, untranslated. There is no en catalogue because the strings in the code are English.

Improving a translation

Catalogues are plain gettext .po files, one per language, in locale/:

locale/fpdb-fr_FR.po
  1. Edit it with any .po editor — Poedit, Lokalize, or a text editor.

  2. Compile and check:

    python tools/compile_translations.py fr_FR

    It prints the message count and where it wrote the .mo.

  3. Run fpdb, switch to that language, and look at the screens you changed. A string that is correct in isolation can still be wrong in a button eight characters wide.

  4. Open a pull request against development with the .po only.

Do not commit .mo files. They are build artifacts and are git-ignored. i18n_compile.py builds them lazily at startup, so a contributor who pulls your .po gets the translation without running anything.

Adding a language

  1. Copy locale/fpdb.pot to locale/fpdb-<code>.po and fill in the header.
  2. Translate.
  3. python tools/compile_translations.py <code>

The language then appears in View → Language on its own: the menu is built from the catalogues actually present, so there is no list to register in.

How it works in the code

Two functions, in fpdb_3_legacy/i18n.py:

from fpdb_3_legacy.i18n import gettext as _
from fpdb_3_legacy.i18n import N_

button = QPushButton(_("Create database"))     # translate now
MENU = (N_("File"), N_("Import"))              # mark now, translate later

_() translates through the catalogue installed at startup, and returns the text unchanged when none is — which is why modules can mark strings without depending on i18n being set up, and why tests do not need a locale.

N_() is a no-op marker. It exists for strings defined at module level, in data that is rendered later: menu_layout.py describes the whole menu bar as data, marked with N_, and translated when Qt menus are actually built. Using _() there would translate at import time, before any language has been chosen, and freeze the menu into whatever locale happened to be active.

A string extractor collects both, with --keyword=N_ for the second.

i18n_compile.py parses .po and writes .mo itself — no msgfmt binary, no babel, no polib. That is why the only prerequisite for working on a translation is a text editor.

For developers adding strings

  • Wrap user-visible strings in _(), or N_() if they are module-level data.
  • Do not build a sentence by concatenation. _("Imported ") + n + _(" hands") cannot be translated into a language that orders those differently. Use a format placeholder: _("Imported %d hands") % n.
  • Leave the placeholders in the string, and keep them named or positional consistently — a translator has to be able to reorder them.
  • After adding strings, refresh locale/fpdb.pot so translators see them.

A note on locale/localise.sh

That script is from the pre-package layout: it runs pygettext over *.py in a flat directory and produces fpdb-en_GB.pot, which is neither the current source layout nor the current template name. Use tools/compile_translations.py; localise.sh is kept for reference and should not be run as-is.

Clone this wiki locally