Zend Framework  3.0
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Translator Class Reference

Translator. More...

Public Member Functions

 setLocale ($locale)
 Set the default locale.
 
 getLocale ()
 Get the default locale.
 
 setFallbackLocale ($locale)
 Set the fallback locale.
 
 getFallbackLocale ()
 Get the fallback locale.
 
 setCache (CacheStorage $cache=null)
 Sets a cache.
 
 getCache ()
 Returns the set cache.
 
 setPluginManager (LoaderPluginManager $pluginManager)
 Set the plugin manager for translation loaders.
 
 getPluginManager ()
 Retrieve the plugin manager for translation loaders.
 
 translate ($message, $textDomain= 'default', $locale=null)
 Translate a message.
 
 translatePlural ($singular, $plural, $number, $textDomain= 'default', $locale=null)
 Translate a plural message.
 
 addTranslationFile ($type, $filename, $textDomain= 'default', $locale=null)
 Add a translation file.
 
 addTranslationFilePattern ($type, $baseDir, $pattern, $textDomain= 'default')
 Add multiple translations with a file pattern.
 
 addRemoteTranslations ($type, $textDomain= 'default')
 Add remote translations.
 
 getAllMessages ($textDomain= 'default', $locale=null)
 Return all the messages.
 
 getEventManager ()
 Get the event manager.
 
 setEventManager (EventManagerInterface $events)
 Set the event manager instance used by this translator.
 
 isEventManagerEnabled ()
 Check whether the event manager is enabled.
 
 enableEventManager ()
 Enable the event manager.
 
 disableEventManager ()
 Disable the event manager.
 

Static Public Member Functions

static factory ($options)
 Instantiate a translator.
 

Public Attributes

const EVENT_MISSING_TRANSLATION = 'missingTranslation'
 Event fired when the translation for a message is missing.
 
const EVENT_NO_MESSAGES_LOADED = 'noMessagesLoaded'
 Event fired when no messages were loaded for a locale/text-domain combination.
 

Protected Member Functions

 getTranslatedMessage ($message, $locale, $textDomain= 'default')
 Get a translated message.
 
 loadMessages ($textDomain, $locale)
 Load messages for a given language and domain.
 
 loadMessagesFromRemote ($textDomain, $locale)
 Load messages from remote sources.
 
 loadMessagesFromPatterns ($textDomain, $locale)
 Load messages from patterns.
 
 loadMessagesFromFiles ($textDomain, $locale)
 Load messages from files.
 

Protected Attributes

 $messages = []
 
 $files = []
 
 $patterns = []
 
 $remote = []
 
 $locale
 
 $fallbackLocale
 
 $cache
 
 $pluginManager
 
 $events
 
 $eventsEnabled = false
 

Detailed Description

Translator.

Member Function Documentation

addRemoteTranslations (   $type,
  $textDomain = 'default' 
)

Add remote translations.

Parameters
string$type
string$textDomain
Returns
Translator
addTranslationFile (   $type,
  $filename,
  $textDomain = 'default',
  $locale = null 
)

Add a translation file.

Parameters
string$type
string$filename
string$textDomain
string$locale
Returns
Translator
addTranslationFilePattern (   $type,
  $baseDir,
  $pattern,
  $textDomain = 'default' 
)

Add multiple translations with a file pattern.

Parameters
string$type
string$baseDir
string$pattern
string$textDomain
Returns
Translator
disableEventManager ( )

Disable the event manager.

Returns
Translator
enableEventManager ( )

Enable the event manager.

Returns
Translator
static factory (   $options)
static

Instantiate a translator.

Parameters
array | Traversable$options
Returns
Translator
Exceptions
Exception\InvalidArgumentException
getAllMessages (   $textDomain = 'default',
  $locale = null 
)

Return all the messages.

Parameters
string$textDomain
null$locale
Returns
mixed
getCache ( )

Returns the set cache.

Returns
CacheStorage The set cache
getEventManager ( )

Get the event manager.

Returns
EventManagerInterface|null
getFallbackLocale ( )

Get the fallback locale.

Returns
string
getLocale ( )

Get the default locale.

Returns
string
Exceptions
Exception\ExtensionNotLoadedExceptionif ext/intl is not present and no locale set
getPluginManager ( )

Retrieve the plugin manager for translation loaders.

Lazy loads an instance if none currently set.

Returns
LoaderPluginManager
getTranslatedMessage (   $message,
  $locale,
  $textDomain = 'default' 
)
protected

Get a translated message.

getTranslatedMessage.missing-translation

Parameters
string$message
string$locale
string$textDomain
Returns
string|null
isEventManagerEnabled ( )

Check whether the event manager is enabled.

Returns
boolean
loadMessages (   $textDomain,
  $locale 
)
protected

Load messages for a given language and domain.

loadMessages.no-messages-loaded

Parameters
string$textDomain
string$locale
Exceptions
Exception\RuntimeException
Returns
void
loadMessagesFromFiles (   $textDomain,
  $locale 
)
protected

Load messages from files.

Parameters
string$textDomain
string$locale
Returns
bool
Exceptions
Exception\RuntimeExceptionWhen specified loader is not a file loader
loadMessagesFromPatterns (   $textDomain,
  $locale 
)
protected

Load messages from patterns.

Parameters
string$textDomain
string$locale
Returns
bool
Exceptions
Exception\RuntimeExceptionWhen specified loader is not a file loader
loadMessagesFromRemote (   $textDomain,
  $locale 
)
protected

Load messages from remote sources.

Parameters
string$textDomain
string$locale
Returns
bool
Exceptions
Exception\RuntimeExceptionWhen specified loader is not a remote loader
setCache ( CacheStorage  $cache = null)

Sets a cache.

Parameters
CacheStorage$cache
Returns
Translator
setEventManager ( EventManagerInterface  $events)

Set the event manager instance used by this translator.

Parameters
EventManagerInterface$events
Returns
Translator
setFallbackLocale (   $locale)

Set the fallback locale.

Parameters
string$locale
Returns
Translator
setLocale (   $locale)

Set the default locale.

Parameters
string$locale
Returns
Translator
setPluginManager ( LoaderPluginManager  $pluginManager)

Set the plugin manager for translation loaders.

Parameters
LoaderPluginManager$pluginManager
Returns
Translator
translate (   $message,
  $textDomain = 'default',
  $locale = null 
)

Translate a message.

Parameters
string$message
string$textDomain
string$locale
Returns
string

Implements TranslatorInterface.

translatePlural (   $singular,
  $plural,
  $number,
  $textDomain = 'default',
  $locale = null 
)

Translate a plural message.

Parameters
string$singular
string$plural
int$number
string$textDomain
string | null$locale
Returns
string
Exceptions
Exception\OutOfBoundsException

Implements TranslatorInterface.

Member Data Documentation

$cache
protected
$events
protected
$eventsEnabled = false
protected
$fallbackLocale
protected
$files = []
protected
$locale
protected
$messages = []
protected
$patterns = []
protected
$pluginManager
protected
$remote = []
protected
const EVENT_MISSING_TRANSLATION = 'missingTranslation'

Event fired when the translation for a message is missing.

const EVENT_NO_MESSAGES_LOADED = 'noMessagesLoaded'

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