Translator.

package Default

 Methods

Add remote translations.

addRemoteTranslations(string $type, string $textDomain = 'default') : \Zend\I18n\Translator\Translator

Parameters

$type

string

$textDomain

string

Returns

\Zend\I18n\Translator\Translator

Add a translation file.

addTranslationFile(string $type, string $filename, string $textDomain = 'default', string $locale = null) : \Zend\I18n\Translator\Translator

Parameters

$type

string

$filename

string

$textDomain

string

$locale

string

Returns

\Zend\I18n\Translator\Translator

Add multiple translations with a file pattern.

addTranslationFilePattern(string $type, string $baseDir, string $pattern, string $textDomain = 'default') : \Zend\I18n\Translator\Translator

Parameters

$type

string

$baseDir

string

$pattern

string

$textDomain

string

Returns

\Zend\I18n\Translator\Translator

Disable the event manager.

disableEventManager() : \Zend\I18n\Translator\Translator

Returns

\Zend\I18n\Translator\Translator

Enable the event manager.

enableEventManager() : \Zend\I18n\Translator\Translator

Returns

\Zend\I18n\Translator\Translator

Instantiate a translator

factory(array|\Traversable $options) : \Zend\I18n\Translator\Translator
Static

Parameters

$options

array\Traversable

Exceptions

\Zend\I18n\Exception\InvalidArgumentException

Returns

\Zend\I18n\Translator\Translator

Returns the set cache

getCache() : \Zend\Cache\Storage\StorageInterface

Returns

\Zend\Cache\Storage\StorageInterfaceThe set cache

Get the event manager.

getEventManager() : \Zend\EventManager\EventManagerInterface | null

Returns

\Zend\EventManager\EventManagerInterfacenull

Get the fallback locale.

getFallbackLocale() : string

Returns

string

Get the default locale.

getLocale() : string

Exceptions

\Zend\I18n\Exception\ExtensionNotLoadedException if ext/intl is not present and no locale set

Returns

string

Retrieve the plugin manager for translation loaders.

getPluginManager() : \Zend\I18n\Translator\LoaderPluginManager

Lazy loads an instance if none currently set.

Returns

\Zend\I18n\Translator\LoaderPluginManager

Check whether the event manager is enabled.

isEventManagerEnabled() : boolean

Returns

boolean

Sets a cache

setCache(\Zend\Cache\Storage\StorageInterface $cache = null) : \Zend\I18n\Translator\Translator

Parameters

$cache

\Zend\Cache\Storage\StorageInterface

Returns

\Zend\I18n\Translator\Translator

Set the event manager instance used by this translator.

setEventManager(\Zend\EventManager\EventManagerInterface $events) : \Zend\I18n\Translator\Translator

Parameters

$events

\Zend\EventManager\EventManagerInterface

Returns

\Zend\I18n\Translator\Translator

Set the fallback locale.

setFallbackLocale(string $locale) : \Zend\I18n\Translator\Translator

Parameters

$locale

string

Returns

\Zend\I18n\Translator\Translator

Set the default locale.

setLocale(string $locale) : \Zend\I18n\Translator\Translator

Parameters

$locale

string

Returns

\Zend\I18n\Translator\Translator

Set the plugin manager for translation loaders

setPluginManager(\Zend\I18n\Translator\LoaderPluginManager $pluginManager) : \Zend\I18n\Translator\Translator

Parameters

$pluginManager

\Zend\I18n\Translator\LoaderPluginManager

Returns

\Zend\I18n\Translator\Translator

Translate a message.

translate(string $message, string $textDomain = 'default', string $locale = null) : string
inherited_from \Zend\I18n\Translator\TranslatorInterface::translate()

Parameters

$message

string

$textDomain

string

$locale

string

Returns

string

Translate a plural message.

translatePlural(string $singular, string $plural, integer $number, string $textDomain = 'default', string|null $locale = null) : string
inherited_from \Zend\I18n\Translator\TranslatorInterface::translatePlural()

Parameters

$singular

string

$plural

string

$number

integer

$textDomain

string

$locale

stringnull

Exceptions

\Zend\I18n\Exception\OutOfBoundsException

Returns

string

Get a translated message.

getTranslatedMessage(string $message, string $locale, string $textDomain = 'default') : string | null
triggers getTranslatedMessage.missing-translation

Parameters

$message

string

$locale

string

$textDomain

string

Returns

stringnull

Load messages for a given language and domain.

loadMessages(string $textDomain, string $locale) : void
triggers loadMessages.no-messages-loaded

Parameters

$textDomain

string

$locale

string

Exceptions

\Zend\I18n\Exception\RuntimeException

Load messages from files.

loadMessagesFromFiles(string $textDomain, string $locale) : boolean

Parameters

$textDomain

string

$locale

string

Exceptions

\Zend\I18n\Exception\RuntimeException When specified loader is not a file loader

Returns

boolean

Load messages from patterns.

loadMessagesFromPatterns(string $textDomain, string $locale) : boolean

Parameters

$textDomain

string

$locale

string

Exceptions

\Zend\I18n\Exception\RuntimeException When specified loader is not a file loader

Returns

boolean

Load messages from remote sources.

loadMessagesFromRemote(string $textDomain, string $locale) : boolean

Parameters

$textDomain

string

$locale

string

Exceptions

\Zend\I18n\Exception\RuntimeException When specified loader is not a remote loader

Returns

boolean

 Properties

 

Translation cache.

$cache : \Zend\Cache\Storage\StorageInterface

Default

 

Event manager for triggering translator events.

$events : \Zend\EventManager\EventManagerInterface

Default

 

Whether events are enabled

$eventsEnabled : boolean

Default

false
 

Locale to use as fallback if there is no translation.

$fallbackLocale : string

Default

 

Files used for loading messages.

$files : array

Default

array()
 

Default locale.

$locale : string

Default

 

Messages loaded by the translator.

$messages : array

Default

array()
 

Patterns used for loading messages.

$patterns : array

Default

array()
 

Plugin manager for translation loaders.

$pluginManager : \Zend\I18n\Translator\LoaderPluginManager

Default

 

Remote locations for loading messages.

$remote : array

Default

array()

 Constants

 

Event fired when the translation for a message is missing.

EVENT_MISSING_TRANSLATION = 'missingTranslation' 
 

Event fired when no messages were loaded for a locale/text-domain combination.

EVENT_NO_MESSAGES_LOADED = 'noMessagesLoaded'