Class Translator
Provides missing message behavior for CakePHP internal message formats.
Constants
-
stringPLURAL_PREFIX ¶'p:'
Property Summary
-
$fallback protected
TranslatorInterfaceA fallback translator.
-
$formatter protected
FormatterInterfaceThe formatter to use when translating messages.
-
$locale protected
stringThe locale being used for translations.
-
$package protected
PackageThe Package containing keys and translations.
Method Summary
-
__construct() public
Constructor
-
getMessage() protected
Gets the message translation by its key.
-
getPackage() public
An object of type Package
-
resolveContext() protected
Resolve a message's context structure.
-
translate() public
Translates the message formatting any placeholders
Method Detail
__construct() ¶ public
__construct(string $locale, Package $package, FormatterInterface $formatter, TranslatorInterface $fallback = null)
Constructor
Parameters
-
string$locale The locale being used.
-
Package$package The Package containing keys and translations.
-
FormatterInterface$formatter A message formatter.
-
TranslatorInterface$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
mixedresolveContext() ¶ protected
resolveContext(string $key, array $message, array $vars): string|array
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
_contextkey.
Returns
string|arraytranslate() ¶ 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