Translator
extends Translator
in package
implements
WarmableInterface
Translator.
Tags
Interfaces, Classes, Traits and Enums
- WarmableInterface
- Interface for classes that support warming their cache.
Table of Contents
- $catalogues : array<string|int, MessageCatalogueInterface>
- $container : mixed
- $loaderIds : mixed
- $options : mixed
- $cacheDir : string
- $cacheVary : mixed
- $configCacheFactory : ConfigCacheFactoryInterface|null
- $debug : bool
- $fallbackLocales : array<string|int, mixed>
- $formatter : MessageFormatterInterface
- $hasIntlFormatter : mixed
- $loaders : array<string|int, LoaderInterface>
- $locale : string
- $parentLocales : array<string|int, mixed>|null
- $resourceFiles : mixed
- $resourceLocales : array<string|int, mixed>
- $resources : array<string|int, mixed>
- Holds parameters from addResource() calls so we can defer the actual parent::addResource() calls until initialize() is executed.
- $scannedDirectories : array<string|int, string>
- __construct() : mixed
- Constructor.
- addLoader() : mixed
- Adds a Loader.
- addResource() : mixed
- Adds a Resource.
- getCatalogue() : MessageCatalogueInterface
- Gets the catalogue by locale.
- getLocale() : string
- Returns the current locale.
- setConfigCacheFactory() : mixed
- setFallbackLocales() : mixed
- Sets the fallback locales.
- setLocale() : mixed
- Sets the current locale.
- trans() : string
- Translates the given message.
- transChoice() : string
- Translates the given choice message by choosing a translation according to a number.
- warmUp() : mixed
- Warms up the cache.
- assertValidLocale() : mixed
- Asserts that the locale is valid, throws an Exception if not.
- computeFallbackLocales() : mixed
- getLoaders() : array<string|int, mixed>
- Gets the loaders.
- initialize() : mixed
- initializeCatalogue() : mixed
- loadCatalogue() : mixed
- addResourceFiles() : 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
= []
$container
protected
mixed
$container
$loaderIds
protected
mixed
$loaderIds
$options
protected
mixed
$options
= ['cache_dir' => null, 'debug' => false, 'resource_files' => [], 'scanned_directories' => [], 'cache_vary' => []]
$cacheDir
private
string
$cacheDir
$cacheVary
private
mixed
$cacheVary
$configCacheFactory
private
ConfigCacheFactoryInterface|null
$configCacheFactory
$debug
private
bool
$debug
$fallbackLocales
private
array<string|int, mixed>
$fallbackLocales
= []
$formatter
private
MessageFormatterInterface
$formatter
$hasIntlFormatter
private
mixed
$hasIntlFormatter
$loaders
private
array<string|int, LoaderInterface>
$loaders
= []
$locale
private
string
$locale
$parentLocales
private
array<string|int, mixed>|null
$parentLocales
$resourceFiles
private
mixed
$resourceFiles
$resourceLocales
private
array<string|int, mixed>
$resourceLocales
$resources
Holds parameters from addResource() calls so we can defer the actual parent::addResource() calls until initialize() is executed.
private
array<string|int, mixed>
$resources
= []
$scannedDirectories
private
array<string|int, string>
$scannedDirectories
Methods
__construct()
Constructor.
public
__construct(ContainerInterface $container, MessageFormatterInterface $formatter, string $defaultLocale[, array<string|int, mixed> $loaderIds = [] ][, array<string|int, mixed> $options = [] ]) : mixed
Available options:
- cache_dir: The cache directory (or null to disable caching)
- debug: Whether to enable debugging or not (false by default)
- resource_files: List of translation resources available grouped by locale.
- cache_vary: An array of data that is serialized to generate the cached catalogue name.
Parameters
- $container : ContainerInterface
- $formatter : MessageFormatterInterface
- $defaultLocale : string
- $loaderIds : array<string|int, mixed> = []
- $options : array<string|int, mixed> = []
Tags
Return values
mixed —addLoader()
Adds a Loader.
public
addLoader(string $format, LoaderInterface $loader) : mixed
Parameters
- $format : string
-
The name of the loader (@see addResource())
- $loader : LoaderInterface
Return values
mixed —addResource()
Adds a Resource.
public
addResource(mixed $format, mixed $resource, mixed $locale[, mixed $domain = null ]) : mixed
Parameters
- $format : mixed
-
The name of the loader (@see addLoader())
- $resource : mixed
-
The resource name
- $locale : mixed
-
The locale
- $domain : mixed = null
-
The domain
Return values
mixed —getCatalogue()
Gets the catalogue by locale.
public
getCatalogue([mixed $locale = null ]) : MessageCatalogueInterface
Parameters
- $locale : mixed = null
-
The locale or null to use the default
Return values
MessageCatalogueInterface —getLocale()
Returns the current locale.
public
getLocale() : string
Return values
string —The locale
setConfigCacheFactory()
public
setConfigCacheFactory(ConfigCacheFactoryInterface $configCacheFactory) : mixed
Parameters
- $configCacheFactory : ConfigCacheFactoryInterface
Return values
mixed —setFallbackLocales()
Sets the fallback locales.
public
setFallbackLocales(array<string|int, mixed> $locales) : mixed
Parameters
- $locales : array<string|int, mixed>
-
The fallback locales
Tags
Return values
mixed —setLocale()
Sets the current locale.
public
setLocale(mixed $locale) : mixed
Parameters
- $locale : mixed
-
The locale
Return values
mixed —trans()
Translates the given message.
public
trans(mixed $id[, array<string|int, mixed> $parameters = [] ][, mixed $domain = null ][, mixed $locale = null ]) : string
Parameters
- $id : mixed
-
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 : mixed = null
-
The domain for the message or null to use the default
- $locale : mixed = null
-
The locale or null to use the default
Return values
string —The translated string
transChoice()
Translates the given choice message by choosing a translation according to a number.
public
transChoice(mixed $id, mixed $number[, array<string|int, mixed> $parameters = [] ][, mixed $domain = null ][, mixed $locale = null ]) : string
Parameters
- $id : mixed
-
The message id (may also be an object that can be cast to string)
- $number : mixed
-
The number to use to find the index of the message
- $parameters : array<string|int, mixed> = []
-
An array of parameters for the message
- $domain : mixed = null
-
The domain for the message or null to use the default
- $locale : mixed = null
-
The locale or null to use the default
Tags
Return values
string —The translated string
warmUp()
Warms up the cache.
public
warmUp(mixed $cacheDir) : mixed
Parameters
- $cacheDir : mixed
-
The cache directory
Return values
mixed —assertValidLocale()
Asserts that the locale is valid, throws an Exception if not.
protected
assertValidLocale(string $locale) : mixed
Parameters
- $locale : string
-
Locale to tests
Tags
Return values
mixed —computeFallbackLocales()
protected
computeFallbackLocales(mixed $locale) : mixed
Parameters
- $locale : mixed
Return values
mixed —getLoaders()
Gets the loaders.
protected
getLoaders() : array<string|int, mixed>
Return values
array<string|int, mixed> —LoaderInterface[]
initialize()
protected
initialize() : mixed
Return values
mixed —initializeCatalogue()
protected
initializeCatalogue(mixed $locale) : mixed
Parameters
- $locale : mixed
Return values
mixed —loadCatalogue()
protected
loadCatalogue(string $locale) : mixed
Parameters
- $locale : string
Return values
mixed —addResourceFiles()
private
addResourceFiles() : mixed
Return values
mixed —dumpCatalogue()
private
dumpCatalogue(string $locale, ConfigCacheInterface $cache) : void
Parameters
- $locale : string
- $cache : ConfigCacheInterface
Return values
void —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
string —getConfigCacheFactory()
Provides the ConfigCache factory implementation, falling back to a default implementation if necessary.
private
getConfigCacheFactory() : ConfigCacheFactoryInterface
Return values
ConfigCacheFactoryInterface —getFallbackContent()
private
getFallbackContent(MessageCatalogue $catalogue) : string
Parameters
- $catalogue : MessageCatalogue
Return values
string —initializeCacheCatalogue()
private
initializeCacheCatalogue(string $locale) : void
Parameters
- $locale : string
Return values
void —loadFallbackCatalogues()
private
loadFallbackCatalogues(string $locale) : void
Parameters
- $locale : string