CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.10 Red Velvet API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 3.10
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Auth
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Filesystem
    • Form
    • Http
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • Shell
    • TestSuite
    • Utility
    • Validation
    • View

Class TranslatorRegistry

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

Namespace: Cake\I18n

Property Summary

  • $_cacher protected
    Cake\Cache\CacheEngine

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

  • $_defaultFormatter protected
    string

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

  • $_fallbackLoader protected
    string

    Fallback loader name

  • $_loaders 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.

  • $_useFallback protected
    bool

    Use fallback-domain for translation loaders.

  • $factory protected
    TranslatorFactory

    A translator factory.

  • $formatters protected
    FormatterLocator

    A formatter locator.

  • $locale protected
    string

    The current locale code.

  • $packages protected
    PackageLocator

    A package locator.

  • $registry protected
    array

    A registry to retain translator objects.

Method Summary

  • __construct() public

    Constructor.

  • _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() protected

    Gets a translator from the registry by package for a locale.

  • _partialLoader() protected

    Returns 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() public

    Gets a translator from the registry by package for a locale.

  • getFactory() public

    The TranslatorFactory object

  • getFormatters() public

    An object of type FormatterLocator

  • getLocale() public

    Returns the default locale code.

  • getPackages() public

    An object of type PackageLocator

  • 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() public

    Set domain fallback for loader.

  • setLocale() public

    Sets the default locale code.

  • useFallback() public

    Set if the default domain fallback is used.

Method Detail

__construct() ¶ public

__construct(PackageLocator $packages, FormatterLocator $formatters, TranslatorFactory $factory, string $locale)

Constructor.

Parameters
PackageLocator $packages

The package locator.

FormatterLocator $formatters

The formatter locator.

TranslatorFactory $factory

A translator factory to create translator objects for the locale and package.

string $locale

The default locale code to use.

_fallbackLoader() ¶ protected

_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

_getFromLoader() ¶ protected

_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

_getTranslator() ¶ protected

_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

_partialLoader() ¶ protected

_partialLoader(): callable

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

Returns
callable

defaultFormatter() ¶ public

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 optional

The name of the formatter to use.

Returns
string

get() ¶ public

get(string $name, string $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 $locale optional

The locale to use; if empty, uses the default locale.

Returns
Aura\Intl\TranslatorInterface|null
Throws
Aura\Intl\Exception
If no translator with that name could be found for the given locale.

getFactory() ¶ public

getFactory(): TranslatorFactory

The TranslatorFactory object

Returns
TranslatorFactory

getFormatters() ¶ public

getFormatters(): FormatterLocator

An object of type FormatterLocator

Returns
FormatterLocator

getLocale() ¶ public

getLocale(): string

Returns the default locale code.

Returns
string

getPackages() ¶ public

getPackages(): PackageLocator

An object of type PackageLocator

Returns
PackageLocator

registerLoader() ¶ public

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

Returns
void

setCacher() ¶ public

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

Sets the CacheEngine instance used to remember translators across requests.

Parameters
Cake\Cache\CacheEngine $cacher

The cacher instance.

Returns
void

setLoaderFallback() ¶ public

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

setLocale() ¶ public

setLocale(string $locale): void

Sets the default locale code.

Parameters
string $locale

The new locale code.

Returns
void

useFallback() ¶ public

useFallback(bool $enable = true): void

Set if the default domain fallback is used.

Parameters
bool $enable optional

flag to enable or disable fallback

Returns
void

Property Detail

$_cacher ¶ protected

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

Type
Cake\Cache\CacheEngine

$_defaultFormatter ¶ protected

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

Type
string

$_fallbackLoader ¶ protected

Fallback loader name

Type
string

$_loaders ¶ protected

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
callable[]

$_useFallback ¶ protected

Use fallback-domain for translation loaders.

Type
bool

$factory ¶ protected

A translator factory.

Type
TranslatorFactory

$formatters ¶ protected

A formatter locator.

Type
FormatterLocator

$locale ¶ protected

The current locale code.

Type
string

$packages ¶ protected

A package locator.

Type
PackageLocator

$registry ¶ protected

A registry to retain translator objects.

Type
array
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs