Translation contexts

When marking strings for translations, there may be certain strings that are used in more than one context, and so may need different translations. In these cases, you should use translation contexts to disambiguate them.

An example for this is "Read" which can mean "to read something" or "something has been read". Another example would be a GUI button labeled "File", which might be disambiguated by adding contextual indication, e.g. 1. "main menu concerning a file" and 2. "to file something somewhere" and have different translations for these two. In any case, only the real string will be translated by the translators, not the contextual part which only serves to disambiguate the string meaning (e.g. in German: 1. "Datei", 2. "Ablegen", obviously both are totally different).

In the normal source code of a glib or gtk-based program, this feature is available by using a special macro instead of the _( ) macro:

  • From glib 2.16 on, the C_( ) macro should be used

  • Before glib 2.16, the Q_( ) macro was used


With GTKBuilder infrastructure, the context information can be specified in its own "context" property, like this:
<property name="foo" translatable="yes" context="context">message</property>

When writing source code too, if you face a case that the same string is used with differing meanings, or is a generic string that has different purposes in different cases like "%d. %s" for example (see below), use a context prefix and use the C_( ) macro instead. When in doubt, ask the gnome-i18n list.


The deprecated LibGlade (that has been replaced by GtkBuilder in most projects) offers this feature through an XML attribute. This means that for translation purposes, one can extend GUI label strings in the glade files and add a disambiguating prefix to them. To activate this, one has to add the disambiguating prefix to the string in the glade file, separated by a '|' from the actual string, and additionally the XML attribute "context" has to be set to "yes" for that property. That attribute can either be added by hand, or in glade-2 you can check the box "Has Content Prefix" when editing a text property.

If you encounter a GUI label anywhere in a glade file that contains a '|' character, please simply ignore the prefix part in front of the '|' when improving the glade dialog. The actual program GUI via libglade will only show the part after the '|'. If anyone wants to add such a disambiguating comment herself/himself, please remember to add the XML attribute 'context="yes"' to the property that contains the disambiguated string.

See also the LibGlade reference manual, section "Internationalization with Libglade". Quote: Libglade also supports disambiguating properties by prefixing them with a |-separated context string, e.g. "Menu/Printer|Open" vs. "Menu/File|Open". You must tell Libglade that the property has a prefix by setting the context attribute of the <property> element to "yes". To learn more about this technique, read the chapter "How to use gettext in GUI programs" in the gettext manual, and see the GLib API documentation for g_strip_context(). (This feature is available since libglade >= 2.3.2, released 2004-01-12.)

TranslationProject/DevGuidelines/Translation contexts (last edited 2018-01-20 15:18:25 by PiotrDrag)