Translator
in package
implements
TranslatorInterface, TranslatorBagInterface
Tags
Interfaces, Classes and Traits
- TranslatorInterface
- TranslatorInterface.
- TranslatorBagInterface
- TranslatorBagInterface.
Table of Contents
- $catalogues : array<string|int, MessageCatalogueInterface>
- $cacheDir : string
- $configCacheFactory : ConfigCacheFactoryInterface|null
- $debug : bool
- $fallbackLocales : array<string|int, mixed>
- $formatter : MessageFormatterInterface
- $loaders : array<string|int, LoaderInterface>
- $locale : string
- $resources : array<string|int, mixed>
- __construct() : mixed
- addLoader() : mixed
- Adds a Loader.
- addResource() : mixed
- Adds a Resource.
- getCatalogue() : MessageCatalogueInterface
- Gets the catalogue by locale.
- getFallbackLocales() : array<string|int, mixed>
- Gets the fallback locales.
- 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.
- assertValidLocale() : mixed
- Asserts that the locale is valid, throws an Exception if not.
- computeFallbackLocales() : mixed
- getLoaders() : array<string|int, mixed>
- Gets the loaders.
- initializeCatalogue() : mixed
- loadCatalogue() : mixed
- doLoadCatalogue() : mixed
- dumpCatalogue() : mixed
- getCatalogueCachePath() : mixed
- getConfigCacheFactory() : ConfigCacheFactoryInterface
- Provides the ConfigCache factory implementation, falling back to a default implementation if necessary.
- getFallbackContent() : mixed
- initializeCacheCatalogue() : mixed
- loadFallbackCatalogues() : mixed
Properties
$catalogues
protected
array<string|int, MessageCatalogueInterface>
$catalogues
= []
$cacheDir
private
string
$cacheDir
$configCacheFactory
private
ConfigCacheFactoryInterface|null
$configCacheFactory
$debug
private
bool
$debug
$fallbackLocales
private
array<string|int, mixed>
$fallbackLocales
= []
$formatter
private
MessageFormatterInterface
$formatter
$loaders
private
array<string|int, LoaderInterface>
$loaders
= []
$locale
private
string
$locale
$resources
private
array<string|int, mixed>
$resources
= []
Methods
__construct()
public
__construct(string $locale[, MessageFormatterInterface|null $formatter = null ][, string|null $cacheDir = null ][, bool $debug = false ]) : mixed
Parameters
- $locale : string
-
The locale
- $formatter : MessageFormatterInterface|null = null
-
The message formatter
- $cacheDir : string|null = null
-
The directory to use for the cache
- $debug : bool = false
-
Use cache in debug mode ?
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
-
A LoaderInterface instance
Return values
mixed —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
-
The locale
- $domain : string = null
-
The domain
Tags
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 —getFallbackLocales()
Gets the fallback locales.
public
getFallbackLocales() : array<string|int, mixed>
Return values
array<string|int, mixed> —The fallback locales
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
Return values
string —The translated string
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[]
initializeCatalogue()
protected
initializeCatalogue(string $locale) : mixed
Parameters
- $locale : string
Return values
mixed —loadCatalogue()
protected
loadCatalogue(string $locale) : mixed
Parameters
- $locale : string
Return values
mixed —doLoadCatalogue()
private
doLoadCatalogue(mixed $locale) : mixed
Parameters
- $locale : mixed
Return values
mixed —dumpCatalogue()
private
dumpCatalogue(mixed $locale, ConfigCacheInterface $cache) : mixed
Parameters
- $locale : mixed
- $cache : ConfigCacheInterface
Return values
mixed —getCatalogueCachePath()
private
getCatalogueCachePath(mixed $locale) : mixed
Parameters
- $locale : mixed
Return values
mixed —getConfigCacheFactory()
Provides the ConfigCache factory implementation, falling back to a default implementation if necessary.
private
getConfigCacheFactory() : ConfigCacheFactoryInterface
Return values
ConfigCacheFactoryInterface —$configCacheFactory
getFallbackContent()
private
getFallbackContent(MessageCatalogue $catalogue) : mixed
Parameters
- $catalogue : MessageCatalogue
Return values
mixed —initializeCacheCatalogue()
private
initializeCacheCatalogue(string $locale) : mixed
Parameters
- $locale : string
Return values
mixed —loadFallbackCatalogues()
private
loadFallbackCatalogues(mixed $locale) : mixed
Parameters
- $locale : mixed