How GIMP Handles Localization and Plural Forms
GIMP achieves global accessibility by relying on the standard GNU gettext framework to translate its user interface into dozens of languages. Handling variations in grammar, particularly the complex plural forms found across different language families, requires a combination of source code markup, standardized translation files, and dynamic evaluation at runtime. This guide explains how GIMP manages internationalization, resolves grammatical pluralities, and compiles localized assets.
The GNU gettext Foundation
GIMP uses GNU gettext for both internationalization (i18n) and
localization (l10n). In the C and Python source code, developers wrap
user-facing strings in standard gettext macros, most commonly
_("Text"). Extraction tools like xgettext scan
the source tree to generate .pot (Portable Object Template)
files. These templates contain every translatable string within the
software, serving as the baseline for volunteer translators working on
language-specific .po files hosted on the GNOME translation
infrastructure.
Managing Plural Variations with ngettext
A major challenge in software localization is that different languages use different rules for pluralization. While English only distinguishes between singular and plural (e.g., "1 layer" versus "2 layers"), languages such as Polish, Russian, and Arabic have three or more plural forms depending on the exact number, while languages like Chinese or Japanese do not alter words for plurals at all.
To handle these variations dynamically without hardcoding English
assumptions, GIMP developers use the ngettext()
function:
ngettext("Export %d image", "Export %d images", n);The function takes three arguments: the default singular string, the default plural string, and the numeric variable determining the count. GIMP passes the integer count to the gettext runtime, which evaluates which grammatical form to display according to the target language's grammatical rules.
Plural-Forms Headers in PO Files
Each language team defines its specific plural logic in the header of
its .po file using a standardized C-style formula. This
header consists of two parameters: nplurals (the total
count of grammatical plural forms) and plural (the
mathematical formula mapping the integer n to the correct
form index).
- English:
Plural-Forms: nplurals=2; plural=(n != 1);
Evaluates to index0for 1, and index1for all other numbers. - Polish:
Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);
Differentiates between single units, numbers ending in 2–4 (excluding teens), and general plurals. - Japanese:
Plural-Forms: nplurals=1; plural=0;
All quantities use the same grammatical string.
Translators then provide a corresponding translation for every evaluated index:
msgid "Export %d image"
msgid_plural "Export %d images"
msgstr[0] "%d Bild exportieren"
msgstr[1] "%d Bilder exportieren"
Runtime Compilation and Locale Fallbacks
Before distribution, GIMP's build system compiles human-readable
.po files into binary .mo (Machine Object)
files using msgfmt. These binary files are installed in
locale-specific directories.
When GIMP launches, it detects the user's desktop environment
language settings using the system locale variables (LANG,
LC_MESSAGES). The software loads the corresponding
.mo catalog into memory. If a specific string or plural
variation has not been translated into the target dialect, gettext falls
back first to the base language, and ultimately to the original
untranslated English string, preventing interface crashes and missing
labels.