Package Home

Zend Framework 2 Documentation (Manual)

PHK Home

File: /modules/zend.i18n.view.helper.translate.plural.html

Size:12004
Storage flags:no_autoload,compress/gzip (30%)

TranslatePlural Helper — Zend Framework 2 2.4.2 documentation

TranslatePlural Helper

The TranslatePlural view helper can be used to translate words which take into account numeric meanings. English, for example, has a singular definition of “car”, for one car. And has the plural definition, “cars”, meaning zero “cars” or more than one car. Other languages like Russian or Polish have more plurals with different rules.

The viewhelper acts as a wrapper for the Zend\I18n\Translator\Translator class.

Setup

Before using the TranslatePlural view helper, you must have first created a Translator object and have attached it to the view helper. If you use the Zend\View\HelperPluginManager to invoke the view helper, this will be done automatically for you.

Basic Usage

1
2
3
4
5
6
7
8
// Within your view
echo $this->translatePlural("car", "cars", $num);

// Use a custom domain
echo $this->translatePlural("monitor", "monitors", $num, "customDomain");

// Change locale
echo $this->translatePlural("locale", "locales", $num, "default", "de_DE");
translatePlural(string $singular, string $plural, int $number[, string $textDomain[, string $locale]])
Parameters:
  • $singular – The singular message to be translated.
  • $plural – The plural message to be translated.
  • $number – The number to evaluate and determine which message to use.
  • $textDomain – (Optional) The text domain where this translation lives. Defaults to the value “default”.
  • $locale – (Optional) Locale in which the message would be translated (locale name, e.g. en_US). If unset, it will use the default locale (Locale::getDefault())

Public Methods

Public methods for setting a Zend\I18n\Translator\Translator and a default text domain are inherited from
Zend\I18n\View\Helper\AbstractTranslatorHelper.

Table Of Contents

This Page

Note: You need to stay logged into your GitHub account to contribute to the documentation.

Edit this document

Edit this document

The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.

  1. Login with your GitHub account.
  2. Go to TranslatePlural Helper on GitHub.
  3. Edit file contents using GitHub's text editor in your web browser
  4. Fill in the Commit message text box at the end of the page telling why you did the changes. Press Propose file change button next to it when done.
  5. On Send a pull request page you don't need to fill in text anymore. Just press Send pull request button.
  6. Your changes are now queued for review under project's Pull requests tab on GitHub.

For more information about the PHK package format: http://phk.tekwire.net