Drupal: Plural Noun Forms For Translated Articles
From this article, you will get know how to configure a module so that when you translate a site to other languages plural forms work correctly.
Solution:
You need to specify the following in the 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 – a number to show
- $singular – line for singular. Don’t use @count there.
- $plural – line for plural. Use @count instead of a number. E.g. , “@count new comments”.
- $args – associative array of replacements which are made after translation (there is no such parameter in Drupal 5 or less). 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: 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)
Note: you don’t need to include @count to this array. This is an automatic replacement for plural forms.
- $langcode – un-compulsory language code for translating to a language which is not used to show a page (there is no such parameter in Drupal 5 or less).
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 then:
msgid “1 day”
msgid_plural “@count days”
msgstr[0] “@count day”
msgstr[1] “@count days”
msgstr[2] “@count days”
Good luck!