Class TranslatorRegistry
Constructs and stores instances of translators that can be retrieved by name and locale.
- Aura\Intl\TranslatorLocator
- Cake\I18n\TranslatorRegistry
Properties summary
-
$_cacher
protectedA CacheEngine object that is used to remember translator across requests.
-
$_defaultFormatter
protectedstring
The name of the default formatter to use for newly created translators from the fallback loader
-
$_fallbackLoader
protectedFallback loader namestring
-
$_loaders
protectedcallable[]
A list of loader functions indexed by domain name. Loaders are callables that are invoked as a default for building translation packages where none can be found for the combination of translator name and locale.
-
$_useFallback
protectedUse fallback-domain for translation loaders.boolean
Method Summary
- __construct() publicConstructor.
- _fallbackLoader() protected
Returns a new translator instance for the given name and locale based of conventions.
- _getFromLoader() protected
Registers a new package by passing the register loaded function for the package name.
- _getTranslator() protectedGets a translator from the registry by package for a locale.
- _partialLoader() protectedReturns a function that can be used as a loader for the registerLoaderMethod
- defaultFormatter() public
Sets the name of the default messages formatter to use for future translator instances.
- get() publicGets a translator from the registry by package for a locale.
- registerLoader() public
Registers a loader function for a package name that will be used as a fallback in case no package with that name can be found.
- setCacher() public
Sets the CacheEngine instance used to remember translators across requests.
- setLoaderFallback() publicSet domain fallback for loader.
- useFallback() publicSet if the default domain fallback is used.
Method Detail
__construct()source public
__construct( Aura\Intl\PackageLocator $packages , Aura\Intl\FormatterLocator $formatters , Cake\I18n\TranslatorFactory $factory , string $locale )
Constructor.
Parameters
- Aura\Intl\PackageLocator
$packages
- The package locator.
- Aura\Intl\FormatterLocator
$formatters
- The formatter locator.
- Cake\I18n\TranslatorFactory
$factory
A translator factory to create translator objects for the locale and package.
- string
$locale
- The default locale code to use.
_fallbackLoader()source protected
_fallbackLoader( string $name , string $locale )
Returns a new translator instance for the given name and locale based of conventions.
Parameters
- string
$name
- The translation package name.
- string
$locale
- The locale to create the translator for.
Returns
Aura\Intl\Translator_getFromLoader()source protected
_getFromLoader( string $name , string $locale )
Registers a new package by passing the register loaded function for the package name.
Parameters
- string
$name
- The name of the translator package
- string
$locale
- The locale that should be built the package for
Returns
Aura\Intl\TranslatorInterfaceA translator object.
_getTranslator()source protected
_getTranslator( string $name , string|null $locale )
Gets a translator from the registry by package for a locale.
Parameters
- string
$name
- The translator package to retrieve.
- string|null
$locale
The locale to use; if empty, uses the default locale.
Returns
Aura\Intl\TranslatorInterfaceA translator object.
_partialLoader()source protected
_partialLoader( )
Returns a function that can be used as a loader for the registerLoaderMethod
Returns
callabledefaultFormatter()source public
defaultFormatter( string|null $name null )
Sets the name of the default messages formatter to use for future translator instances.
If called with no arguments, it will return the currently configured value.
Parameters
- string|null
$name
optional null - The name of the formatter to use.
Returns
stringThe name of the formatter.
get()source public
get( string $name , string|null $locale null )
Gets a translator from the registry by package for a locale.
Parameters
- string
$name
- The translator package to retrieve.
- string|null
$locale
optional null The locale to use; if empty, uses the default locale.
Returns
Aura\Intl\TranslatorInterface|nullA translator object.
Throws
Aura\Intl\ExceptionIf no translator with that name could be found for the given locale.
registerLoader()source public
registerLoader( string $name , callable $loader )
Registers a loader function for a package name that will be used as a fallback in case no package with that name can be found.
Loader callbacks will get as first argument the package name and the locale as the second argument.
Parameters
- string
$name
- The name of the translator package to register a loader for
- callable
$loader
- A callable object that should return a Package
setCacher()source public
setCacher( Cake\Cache\CacheEngine $cacher )
Sets the CacheEngine instance used to remember translators across requests.
Parameters
-
Cake\Cache\CacheEngine
$cacher
- The cacher instance.
setLoaderFallback()source public
setLoaderFallback( string $name , callable $loader )
Set domain fallback for loader.
Parameters
- string
$name
- The name of the loader domain
- callable
$loader
- invokable loader
Returns
callableloader
useFallback()source public
useFallback( boolean $enable true )
Set if the default domain fallback is used.
Parameters
- boolean
$enable
optional true - flag to enable or disable fallback
Properties detail
$_cachersource
protected Cake\Cache\CacheEngine
A CacheEngine object that is used to remember translator across requests.
$_defaultFormattersource
protected string
The name of the default formatter to use for newly created translators from the fallback loader
'default'
$_loaderssource
protected callable[]
A list of loader functions indexed by domain name. Loaders are callables that are invoked as a default for building translation packages where none can be found for the combination of translator name and locale.
[]
© 2005–2017 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.4/class-Cake.I18n.TranslatorRegistry.html