On this page
View Helpers
Introduction
laminas-i18n ships with a set of laminas-view helper classes related to internationalization.
These helpers are based on Laminas component for the view layer: laminas-view and their helpers.
Installation Requirements
The view-helper support of laminas-i18n depends on the laminas-view component, so be sure to have it installed before getting started:
$ composer require laminas/laminas-viewIDE Auto-Completion in Templates
The Laminas\I18n\View\HelperTrait trait can be used to provide auto-completion for modern IDEs. It defines the aliases of the view helpers in a DocBlock as @method tags.
Usage
In order to allow auto-completion in templates, $this variable should be type-hinted via a DocBlock at the top of a template.
It is recommended that> always the Laminas\View\Renderer\PhpRenderer is added as the first type, so that the IDE can auto-suggest the default view helpers from laminas-view.
The HelperTrait from laminas-i18n can be chained with a pipe symbol (a.k.a. vertical bar) |:
/**
 * @var Laminas\View\Renderer\PhpRenderer|Laminas\I18n\View\HelperTrait $this
 */The HelperTrait traits can be chained as many as needed, depending on which view helpers from the different Laminas component are used and where the auto-completion is to be made.
Abstract Translator Helper
The AbstractTranslatorHelper view helper is used as a base abstract class for
any helpers that need to translate content. It provides an implementation for
the Laminas\I18n\Translator\TranslatorAwareInterface, allowing translator
injection as well as text domain injection.
Public Methods
setTranslator()
setTranslator(Translator $translator, string $textDomain = null) : voidSets the Laminas\I18n\Translator\Translator instance to use in the helper. The
$textDomain argument is optional, and provided as a convenienct to allow
setting both the translator and text domain simultaneously.
getTranslator()
getTranslator() : TranslatorReturns the Laminas\I18n\Translator\Translator instance used by the helper.
hasTranslator()
hasTranslator() : boolReturns true if the helper composes a Laminas\I18n\Translator\Translator
instance.
setTranslatorEnabled()
setTranslatorEnabled(bool $enabled) : voidSets whether or not translations are enabled.
isTranslatorEnabled()
isTranslatorEnabled() : boolReturns true if translations are enabled.
setTranslatorTextDomain()
setTranslatorTextDomain(string $textDomain) : voidSets the default translation text domain to use with the helper.
getTranslatorTextDomain()
getTranslatorTextDomain() : stringReturns the current text domain used by the helper.