W3cubDocs

/CakePHP 4.4

Class Translator

Translator to translate the message.

Namespace: Cake\I18n

Constants

  • string
    PLURAL_PREFIX
    'p:'

Property Summary

  • $fallback protected
    Cake\I18n\Translator|null

    A fallback translator.

  • $formatter protected
    Cake\I18n\FormatterInterface

    The formatter to use when translating messages.

  • $locale protected
    string

    The locale being used for translations.

  • $package protected
    Cake\I18n\Package

    The Package containing keys and translations.

Method Summary

Method Detail

__construct() public

__construct(string $locale, Cake\I18n\Package $package, Cake\I18n\FormatterInterface $formatter, Cake\I18n\Translator|null $fallback = null)

Constructor

Parameters

string $locale

The locale being used.

Cake\I18n\Package $package

The Package containing keys and translations.

Cake\I18n\FormatterInterface $formatter

A message formatter.

Cake\I18n\Translator|null $fallback optional

A fallback translator.

getMessage() protected

getMessage(string $key): mixed

Gets the message translation by its key.

Parameters

string $key

The message key.

Returns

mixed

getPackage() public

getPackage(): Cake\I18n\Package

Returns the translator package

Returns

Cake\I18n\Package

resolveContext() protected

resolveContext(string $key, array $message, array $vars): array|string

Resolve a message's context structure.

Parameters

string $key

The message key being handled.

array $message

The message content.

array $vars

The variables containing the _context key.

Returns

array|string

translate() public

translate(string $key, array $tokensValues = []): string

Translates the message formatting any placeholders

Parameters

string $key

The message key.

array $tokensValues optional

Token values to interpolate into the message.

Returns

string

Property Detail

$fallback protected

A fallback translator.

Type

Cake\I18n\Translator|null

$formatter protected

The formatter to use when translating messages.

Type

Cake\I18n\FormatterInterface

$locale protected

The locale being used for translations.

Type

string

$package protected

The Package containing keys and translations.

Type

Cake\I18n\Package

© 2005–present 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/4.4/class-Cake.I18n.Translator.html