Translator
in package
implements
TranslatorInterface, TranslatorBagInterface, LocaleAwareInterface
Tags
Table of Contents
Interfaces
Properties
- $catalogues : array<string|int, MessageCatalogueInterface>
- $cacheDir : string|null
- $cacheVary : array<string|int, mixed>
- $configCacheFactory : mixed
- $debug : bool
- $fallbackLocales : array<string|int, string>
- $formatter : mixed
- $hasIntlFormatter : bool
- $loaders : array<string|int, LoaderInterface>
- $locale : string
- $parentLocales : array<string|int, mixed>
- $resources : array<string|int, mixed>
Methods
- __construct() : mixed
- addLoader() : mixed
- Adds a Loader.
- addResource() : mixed
- Adds a Resource.
- getCatalogue() : MessageCatalogueInterface
- Gets the catalogue by locale.
- getCatalogues() : array<string|int, MessageCatalogueInterface>
- Returns all catalogues of the instance.
- getLocale() : string
- Returns the default locale.
- setConfigCacheFactory() : mixed
- setFallbackLocales() : mixed
- Sets the fallback locales.
- setLocale() : mixed
- Sets the current locale.
- trans() : string
- Translates the given message.
- assertValidLocale() : mixed
- Asserts that the locale is valid, throws an Exception if not.
- computeFallbackLocales() : mixed
- getLoaders() : array<string|int, LoaderInterface>
- Gets the loaders.
- initializeCatalogue() : mixed
- loadCatalogue() : mixed
- dumpCatalogue() : void
- getAllMessages() : array<string|int, mixed>
- getCatalogueCachePath() : string
- getConfigCacheFactory() : ConfigCacheFactoryInterface
- Provides the ConfigCache factory implementation, falling back to a default implementation if necessary.
- getFallbackContent() : string
- initializeCacheCatalogue() : void
- loadFallbackCatalogues() : void
Properties
$catalogues
protected
array<string|int, MessageCatalogueInterface>
$catalogues
= []
$cacheDir
private
string|null
$cacheDir
$cacheVary
private
array<string|int, mixed>
$cacheVary
$configCacheFactory
private
mixed
$configCacheFactory
$debug
private
bool
$debug
$fallbackLocales
private
array<string|int, string>
$fallbackLocales
= []
$formatter
private
mixed
$formatter
$hasIntlFormatter
private
bool
$hasIntlFormatter
$loaders
private
array<string|int, LoaderInterface>
$loaders
= []
$locale
private
string
$locale
$parentLocales
private
array<string|int, mixed>
$parentLocales
$resources
private
array<string|int, mixed>
$resources
= []
Methods
__construct()
public
__construct(string $locale[, MessageFormatterInterface $formatter = null ][, string $cacheDir = null ][, bool $debug = false ][, array<string|int, mixed> $cacheVary = [] ]) : mixed
Parameters
- $locale : string
- $formatter : MessageFormatterInterface = null
- $cacheDir : string = null
- $debug : bool = false
- $cacheVary : array<string|int, mixed> = []
Tags
addLoader()
Adds a Loader.
public
addLoader(string $format, LoaderInterface $loader) : mixed
Parameters
- $format : string
-
The name of the loader (@see addResource())
- $loader : LoaderInterface
addResource()
Adds a Resource.
public
addResource(string $format, mixed $resource, string $locale[, string $domain = null ]) : mixed
Parameters
- $format : string
-
The name of the loader (@see addLoader())
- $resource : mixed
-
The resource name
- $locale : string
- $domain : string = null
Tags
getCatalogue()
Gets the catalogue by locale.
public
getCatalogue([string $locale = null ]) : MessageCatalogueInterface
Parameters
- $locale : string = null
-
The locale or null to use the default
Return values
MessageCatalogueInterfacegetCatalogues()
Returns all catalogues of the instance.
public
getCatalogues() : array<string|int, MessageCatalogueInterface>
Return values
array<string|int, MessageCatalogueInterface>getLocale()
Returns the default locale.
public
getLocale() : string
Return values
stringsetConfigCacheFactory()
public
setConfigCacheFactory(ConfigCacheFactoryInterface $configCacheFactory) : mixed
Parameters
- $configCacheFactory : ConfigCacheFactoryInterface
setFallbackLocales()
Sets the fallback locales.
public
setFallbackLocales(array<string|int, string> $locales) : mixed
Parameters
- $locales : array<string|int, string>
Tags
setLocale()
Sets the current locale.
public
setLocale(string $locale) : mixed
Parameters
- $locale : string
trans()
Translates the given message.
public
trans(string|null $id[, array<string|int, mixed> $parameters = [] ][, string $domain = null ][, string $locale = null ]) : string
Parameters
- $id : string|null
-
The message id (may also be an object that can be cast to string)
- $parameters : array<string|int, mixed> = []
-
An array of parameters for the message
- $domain : string = null
-
The domain for the message or null to use the default
- $locale : string = null
-
The locale or null to use the default
Return values
stringassertValidLocale()
Asserts that the locale is valid, throws an Exception if not.
protected
assertValidLocale(string $locale) : mixed
Parameters
- $locale : string
Tags
computeFallbackLocales()
protected
computeFallbackLocales(string $locale) : mixed
Parameters
- $locale : string
getLoaders()
Gets the loaders.
protected
getLoaders() : array<string|int, LoaderInterface>
Return values
array<string|int, LoaderInterface>initializeCatalogue()
protected
initializeCatalogue(string $locale) : mixed
Parameters
- $locale : string
loadCatalogue()
protected
loadCatalogue(string $locale) : mixed
Parameters
- $locale : string
dumpCatalogue()
private
dumpCatalogue(string $locale, ConfigCacheInterface $cache) : void
Parameters
- $locale : string
- $cache : ConfigCacheInterface
getAllMessages()
private
getAllMessages(MessageCatalogueInterface $catalogue) : array<string|int, mixed>
Parameters
- $catalogue : MessageCatalogueInterface
Return values
array<string|int, mixed>getCatalogueCachePath()
private
getCatalogueCachePath(string $locale) : string
Parameters
- $locale : string
Return values
stringgetConfigCacheFactory()
Provides the ConfigCache factory implementation, falling back to a default implementation if necessary.
private
getConfigCacheFactory() : ConfigCacheFactoryInterface
Return values
ConfigCacheFactoryInterfacegetFallbackContent()
private
getFallbackContent(MessageCatalogue $catalogue) : string
Parameters
- $catalogue : MessageCatalogue
Return values
stringinitializeCacheCatalogue()
private
initializeCacheCatalogue(string $locale) : void
Parameters
- $locale : string
loadFallbackCatalogues()
private
loadFallbackCatalogues(string $locale) : void
Parameters
- $locale : string