\Cake\I18nTranslatorRegistry

Constructs and stores instances of translators that can be retrieved by name and locale.

Summary

Methods
Properties
Constants
__construct()
setLocale()
getLocale()
getFactory()
getPackages()
getFormatters()
get()
setCacher()
registerLoader()
defaultFormatter()
useFallback()
setLoaderFallback()
No public properties found
No constants found
_getTranslator()
_fallbackLoader()
_partialLoader()
_getFromLoader()
$registry
$locale
$factory
$packages
$formatters
$_loaders
$_fallbackLoader
$_defaultFormatter
$_useFallback
$_cacher
N/A
No private methods found
No private properties found
N/A

Properties

$registry

$registry : array

A registry to retain translator objects.

Type

array

$locale

$locale : string

The current locale code.

Type

string

$_loaders

$_loaders : array<mixed,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.

Type

array<mixed,callable>

$_fallbackLoader

$_fallbackLoader : string

Fallback loader name

Type

string

$_defaultFormatter

$_defaultFormatter : string

The name of the default formatter to use for newly created translators from the fallback loader

Type

string

$_useFallback

$_useFallback : boolean

Use fallback-domain for translation loaders.

Type

boolean

$_cacher

$_cacher : \Cake\Cache\CacheEngine

A CacheEngine object that is used to remember translator across requests.

Type

\Cake\Cache\CacheEngine

Methods

__construct()

__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.

setLocale()

setLocale(string  $locale) : void

Sets the default locale code.

Parameters

string $locale

The new locale code.

getLocale()

getLocale() : string

Returns the default locale code.

Returns

string

get()

get(string  $name, string|null  $locale = null) : \Aura\Intl\TranslatorInterface|null

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.

Throws

\Aura\Intl\Exception

If no translator with that name could be found for the given locale.

Returns

\Aura\Intl\TranslatorInterface|null —

A translator object.

setCacher()

setCacher(\Cake\Cache\CacheEngine  $cacher) : void

Sets the CacheEngine instance used to remember translators across requests.

Parameters

\Cake\Cache\CacheEngine $cacher

The cacher instance.

registerLoader()

registerLoader(string  $name, callable  $loader) : void

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

defaultFormatter()

defaultFormatter(string|null  $name = null) : string

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

The name of the formatter to use.

Returns

string —

The name of the formatter.

useFallback()

useFallback(boolean  $enable = true) : void

Set if the default domain fallback is used.

Parameters

boolean $enable

flag to enable or disable fallback

setLoaderFallback()

setLoaderFallback(string  $name, callable  $loader) : callable

Set domain fallback for loader.

Parameters

string $name

The name of the loader domain

callable $loader

invokable loader

Returns

callable —

loader

_getTranslator()

_getTranslator(string  $name, string|null  $locale) : \Aura\Intl\TranslatorInterface

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\TranslatorInterface

A translator object.

_fallbackLoader()

_fallbackLoader(string  $name, string  $locale) : \Aura\Intl\Translator

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

_partialLoader()

_partialLoader() : callable

Returns a function that can be used as a loader for the registerLoaderMethod

Returns

callable

_getFromLoader()

_getFromLoader(string  $name, string  $locale) : \Aura\Intl\TranslatorInterface

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\TranslatorInterface

A translator object.