View Helpers
In This Article
Translate
The Translate view helper can be used to translate content. It acts as a
wrapper for the Zend\I18n\Translator\Translator class.
Setup
Before using the Translate 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
echo $this->translate('Some translated text.'); // Etwas übersetzter Text
(The above example assumes that the environment locale is set to de_DE.)
Using Text Domain
The text domain defines the domain of the translation.
echo $this->translate('monitor', 'customDomain'); // 'Monitor'$this->plugin('currencyFormat')->setTranslatorTextDomain('customDomain');
echo $this->translate('monitor'); // 'Monitor'(The above example assumes that the environment locale is set to de_DE.)
Get Current Value
To get the current value of this option, use the getTranslatorTextDomain()
method.
$this->plugin('translatePlural')->setTranslatorTextDomain('customDomain');
echo $this->plugin('translatePlural')->getTranslatorTextDomain(); // 'customDomain'
Default Value
The default value of this option is default like defined in
Zend\I18n\Translator\TranslatorInterface.
Using Locale
The locale to which the message should be translated.
echo $this->translate('car', 'default', 'de_DE'); // 'Auto'
Default Value
By default, if no locale is provided, TranslatePlural will use the system
locale provide by PHP's Locale::getDefault().
Found a mistake or want to contribute to the documentation? Edit this page on GitHub!