Plurals

In many cases, a static string is insufficient for proper localized content. For these cases, the stylesheets allow for alternate strings by placing the strings in a structured XML fragment. Alternate strings are used in two ways: to provide plural forms according to the plural rules of the language, and to provide alternate formattings based on a specified role. This section discusses plurals. See Section 5.3 ― Roles for a discussion of roles.

Plural forms are handled similarly to how they are handled in other applications. A rule is provided to transform a number into a plural index, and a translation is provided for each of those indexes. Unfortunately, there is no standard way to encode this information into XML; thus, there is no mechanism in intltool's XML mode. Consequently, translators must place their translations in an XML fragment. This fragment is merged into the l10n.xml file, and the stylesheets extract the appropriate form.

Here is an example entry in the l10n.xml file:

<msgset xmlns=""http://www.gnome.org/~shaunm/gnome-doc-utils/l10n">
  <msgid>Author</msgid>
  <msg>
    <msgstr form='0'>Author</msgstr>
    <msgstr form='1'>Authors</msgstr>
  </msg>
  <msg xml:lang="sr">
    <msgstr form='0'>Аутор</msgstr>
    <msgstr form='1'>Аутори</msgstr>
    <msgstr form='2'>Аутори</msgstr>
  </msg>
</msgset>

Since the Serbian language has three plural forms, three translations have been provided. Each of these is placed in a msgstr element, and the form attribute is used to indicate for which plural form they are used.

Again, translators will only see the entries in their PO files. The PO file entry for the above translation looks like this:

#. Used as a header before a list of authors.
#: ../xslt/gettext/l10n.xml.in.h:1310
msgid ""
"<msgstr form='0'>Author</msgstr> "
"<msgstr form='1'>Authors</msgstr>"
msgstr ""
"<msgstr form='0'>Аутор</msgstr>\n"
"<msgstr form='1'>Аутори</msgstr>\n"
"<msgstr form='2'>Аутори</msgstr>"

Since intltool often alters whitespace, the entry in the PO file might not look as nice as this. When creating the translated message strings, translators may add or remove whitespace between msgstr elements if they choose. This extra text content is ignored by l10n.gettext.

Note that translators may add a msgstr element without a form attribute as a fallback translation. In the example above, the last two msgstr elements could have been replaced by a single msgstr element without a form attribute. The l10n.gettext template would match the first element whenever the plural form is 0, and the fallback element otherwise.

The plural form is selected using the l10n.plural.form template. This templates takes the number of items as a parameter, and returns the numeric index of the plural form to use. Currently, the rule cannot be automatically extracted from the Plural-Forms entry in the PO file, though this feature is planned for the future. Until this feature is added, plural rules have to be coded manually in the stylesheets. Translators need to notify the maintainers when they begin translating the stylesheets.