Embedding plural forms into translations

Introduction
Different languages have different rules for selecting which form of a word to use depending on an associated item count. English says "0 images", "1 image", "2+ images". French says "0 image", "1 image", "2+ images" (that is, it treats 0 as 1, whereas English treats 0 as 2 and above.) Other languages (such as Russian) have 2 forms for the plural. Others yet (eg, Hungarian) have no distinct singular and plural and hence only one form. None of the supported languages has more than 3 forms (singular, plural1, plural2). The acceptable forms are singular|plural1|plural2, singular|plural , and singular , depending on the language. (The last one is probably better written as singular, but is included for completeness.) In those examples,  is the variable holding the number of items. Note that the actual number should be in the same translation string as the plural list, as some languages could conceivably place the item count after the item name, not before.

Detailed rules
English (and all languages not listed below): singular|plural


 * is used when  is 1.
 * is used in all other cases, including 0.

Russian, Ukrainian, and Belarusian:

singular|plural1|plural2


 * is used when  is or ends in 1, except when it is or ends in 11.
 * is used when  is or ends in 2, 3, or 4, except when it is or ends in 12, 13 or 14.
 * is used in all other cases, including 0.

French and Brazilian Portuguese:

singular|plural


 * is used when  is 0 or 1.
 * is used in all other cases, that is when  is 2 or more.

Lithuanian:

singular|plural1|plural2


 * is used when  is or ends in 1, except when it is or ends in 11.
 * is used in all cases besides those described in  or.
 * is used when  is 0 or within range 10-19; the last two digits of   are in range 10-19; or   is a multiple of 10.

Polish:

singular|plural1|plural2


 * is used when  is 1.
 * is used when  is or ends in 2, 3, or 4, except when it is or ends in 12, 13 or 14.
 * is used in all other cases, including 0.

Hungarian, Japanese, and Turkish:

singular


 * is always used. (as noted above, this is silly, but LiveJournal lets you do it, so...)

Latvian:

singular|plural|nullar


 * is used when  is or ends in 1, except when it is or ends in 11.
 * is used in all cases besides those described in  or.
 * is used when  is 0.

Icelandic:

singular|plural


 * is used when  is or ends in 1, except when it is or ends in 11.
 * is used in all other cases, including 0.

A practical example
A page discussing calendars may mention the number of days in a given month. That reference, in the untranslated English version, may look like monthdays day|days. In this hypothetical example, monthdays would be replaced by the actual number of days in the month before the page is sent to the user, and you should copy it verbatim to your translation. In addition, you should replace day|days with the appropriate rule for your language; that rule would typically include appropriate translations for "day" and "days" (including any additional forms your language may use). Thus, the French translation would be monthdays jour|jours. Also, if your language wants the count in another position than just before the item name, you should move monthdays to its proper position in the translated text.

Tricks, special cases, and historical oddities
Some translation strings introduced before the plural feature existed have two versions, one for the singular and one for the plural. An example is:

Code: /userinfo.bml.timeupdate.dayago English (LJ): 1 day ago

Code: /userinfo.bml.timeupdate.daysago English (LJ): num days ago

which would normally be written as

Code: /userinfo.bml.timeupdate.daysago English (LJ): num day|days ago

(with a single string for both singular and plural.) The ?... sequence can be used in translations even if the original English text doesn't use it, as long as the English uses num. Thus, for those languages with pluralization rules that don't match English, you could have (in French) il y a num jour|jours for the plural strings (or suitable equivalents for other languages), even though that string in English doesn't use ?... and only uses num. However, it couldn't be used for the singular, which uses neither ?... nor num.

Credits
Draft translation from the Perl code by pauamma. Corrections and rewording for clarity by camomiletea and janinedog. Tricks section based on a suggestion by parasti in lj_latvian.