Package Home

Zend Framework 2 Documentation (Manual)

PHK Home

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

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

Translate Helper — Zend Framework 2 2.4.2 documentation

Translate Helper

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

1
2
3
4
5
6
7
8
9
// Within your view

echo $this->translate("Some translated text.");

echo $this->translate("Translated text from a custom text domain.", "customDomain");

echo sprintf($this->translate("The current time is %s."), $currentTime);

echo $this->translate("Translate in a specific locale", "default", "de_DE");
translate(string $message[, string $textDomain[, string $locale]])
Parameters:
  • $message – The message to be translated.
  • $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())

Gettext

The xgettext utility can be used to compile *.po files from PHP source files containing the translate view helper.

xgettext --language=php --add-location --keyword=translate my-view-file.phtml

See the Gettext Wikipedia page for more information.

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 Translate 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