Задача
Необходимо в модуле задать строки так, чтобы работали множественные формы при переводе на другие языки.
Решение
В коде нужно указать:
format_plural($day_count, '1 day', '@count days');
Формат функции format_plural():
D6: format_plural($count, $singular, $plural, $args = array(), $langcode = NULL)
D5: format_plural($count, $singular, $plural)
D5: format_plural($count, $singular, $plural)
Параметры
- $count - число, которое нужно показать.
- $singular - строка для единственного числа. Не используйте @count в строке с единственным числом.
- $plural - строка для множественного числа. Используйте @count в том месте, где нужно вставить число. Например, "@count new comments".
- $args - ассоциативный массив замен, которые делаются после перевода (параметра нет в Друпал 5 и ниже). 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: вставляется как есть
- @variable: escape plain text to HTML (check_plain)
- %variable: escape text and theme as a placeholder for user-submitted content (check_plain + theme_placeholder)
ВНИМАНИЕ: вам не нужно включать @count в этот массив. Эта замена делается автоматически для множественных форм.
- $langcode - не обязательный код языка для перевода на язык отличный от того, который используется для показа страницы (параметра нет в Друпал 5 и ниже).
Пример:
$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)));
'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-файле после извлечения строк и перевода будет след. код:
msgid "1 day"
msgid_plural "@count days"
msgstr[0] "@count день"
msgstr[1] "@count дня"
msgstr[2] "@count дней"
msgid_plural "@count days"
msgstr[0] "@count день"
msgstr[1] "@count дня"
msgstr[2] "@count дней"
Использованные материалы
Полезные ссылки
Bookmark/Search this post with










