Drupal: Plural for Translated Modules
So, you should create lines in your Drupal module as to plural work when translating to other languages.
You should specify in module’s code:
format_plural($day_count, ‘1 day’, ‘@count days’);
Format of format_plural() function:
D6: format_plural($count, $singular, $plural, $args = array(), $langcode = NULL)
D5: format_plural($count, $singular, $plural)
Parameters:
- $count – number to be shown.
- $singular – line for singular. Do not use @count in this line.
- $plural – line for plural. Use @count where number should be placed. For example "@count new comments".
- $args – associative array of replacements which are made after translation(there is no such parameter in Drupal 5 and lower). Incidences of any key in this array are replaced with the corresponding value. Based on the first character of the key, the value is escaped and/or themed:
- !variable: is inserted as is
- @variable: escape plain text to HTML (check_plain)
- %variable: escape text and theme as a placeholder for user-submitted content (check_plain + theme_placeholder)
ATTENTION: you do not need to include @count to this array. This replacement is made automatically for prural.
- $langcode – unnecessary code of language different from language that is used to show page (there is no such parameter in Drupal 5 and lower).
Example:
$output = format_plural($update_count,
‘Changed the content type of 1 post from %old-type to %new-type.’,
‘Changed the content type of @count posts from %old-type to %new-type.’,
array(‘%old-type’ => $info->old_type, ‘%new-type’ => $info->new_type)));
Po-file will contain the following code after extracting of lines and translation:
msgid "1 day"
msgid_plural "@count days"
msgstr[0] "@count day"
msgstr[1] "@count day"
msgstr[2] "@count days"