format_plural

Хочешь помочь с переводом? Это очень просто и быстро. Лишь зарегистрируйся, и можешь тут же начать переводить.

includes/common.inc, строка 1072

Версии
5
format_plural($count, $singular, $plural)
6
format_plural($count, $singular, $plural, $args = array(), $langcode = NULL)

Форматирует и переводит строку, содержащую число.

Функция обеспечивает корректное форматирование и перевод строк с числителями. Так как функция вызыват t(), не передавайте в нее уже переведенные значения.

Параметры

$count Число для подстановки.

$singular Строка в единичном числе. Используйте строки, в которых явно выраженно единичное число, дабы упростить дальнейший перевод (напр. используйте "1 new comment" вместо "1 new"). Кроме того, здесь запрещено использовать @count.

$plural Строка для множественного значения. Используйте '@count' в месте, где должна подставиться цифра, например

'@count
new comments'
.

Возвращаемое значение

Переведенная строка.

Связанные темы

▾ 22 функции вызывают format_plural()

aggregator_view in modules/aggregator/aggregator.module
comment_link in modules/comment/comment.module
Реализация hook_link().
comment_nodeapi in modules/comment/comment.module
Реализация hook_nodeapi().
format_interval in includes/common.inc
Форматирует временной интервал с заданной точностью.
format_size in includes/common.inc
Генерирует строчное представление указанного количества байт.
hook_link in developer/hooks/core.php
Определяет внутренние ссылки Drupal.
node_node_type in modules/node/content_types.inc
Implementation of hook_node_type().
node_title_list in modules/node/node.module
Gather a listing of links to nodes.
node_type_delete_confirm in modules/node/content_types.inc
Menu callback; delete a single content type.
poll_page in modules/poll/poll.module
poll_view_results in modules/poll/poll.module
Generates a graphical representation of the results of a poll.
search_admin_settings in modules/search/search.module
Menu callback; displays the search module settings page.
statistics_link in modules/statistics/statistics.module
Реализация hook_link().
system_modules_confirm_form in modules/system/system.module
theme_forum_list in modules/forum/forum.module
Format the forum listing.
theme_forum_topic_list in modules/forum/forum.module
Format the topic listing.
throttle_exit in modules/throttle/throttle.module
Implementation of hook_exit().
tracker_page in modules/tracker/tracker.module
Menu callback. Prints a listing of active nodes on the site.
upload_link in modules/upload/upload.module
Реализация hook_link().
upload_nodeapi in modules/upload/upload.module
Implementation of hook_nodeapi().
user_block in modules/user/user.module
Реализация hook_block().
_aggregator_items in modules/aggregator/aggregator.module
Helper function for drupal_map_assoc.

Код

<?php
function format_plural($count, $singular, $plural) {
  if ($count == 1) return t($singular, array("@count" => $count));

  // get the plural index through the gettext formula
  $index = (function_exists('locale_get_plural')) ? locale_get_plural($count) : -1;
  if ($index < 0) { // backward compatibility
    return t($plural, array("@count" => $count));
  }
  else {
    switch ($index) {
      case "0":
        return t($singular, array("@count" => $count));
      case "1":
        return t($plural, array("@count" => $count));
      default:
        return t(strtr($plural, array("@count" => '@count['. $index .']')), array('@count['. $index .']' => $count));
    }
  }
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии

Вход в систему