Skip to content

SimpleTranslator

SimpleTranslator defines the translator which loads the data from its parameters.

class SimpleTranslator extends BasicTranslator

ExtendsBasicTranslator
Since1.0.0
SourceTranslation/SimpleTranslator.php
MethodDescription
initialize(Context $context, array<string, mixed> $parameters = []): voidInitialize this Translator.
localeChanged(QuioteLocale $newLocale): mixedThis method gets called by the translation manager when the default locale has been changed.
reset(): voidReset per-request locale state for worker compatibility.
translate(mixed $message, string $domain, ?QuioteLocale $locale = null): stringTranslates a message into the defined language.

public function initialize(Context $context, array<string, mixed> $parameters = []): void

Initialize this Translator.

An associative array of initialization parameters

ParameterTypeDescription
$contextContextThe current application context.
$parametersarray``<``string``, ``mixed``>An associative array of initialization parameters

public function localeChanged(QuioteLocale $newLocale): mixed

This method gets called by the translation manager when the default locale has been changed.

The new default locale.

ParameterTypeDescription
$newLocaleQuioteLocaleThe new default locale.

Returns mixed

public function reset(): void

Reset per-request locale state for worker compatibility.

domainData is the parsed config catalog built once in initialize() and never restored afterward — clearing it here would leave every subsequent request’s translations resolving to their untranslated key for the rest of the worker’s lifetime. Only currentData/locale, which localeChanged() re-derives from domainData for the active locale, are per-request.

public function translate(mixed $message, string $domain, ?QuioteLocale $locale = null): string

Translates a message into the defined language.

The locale to which the message should be translated.

ParameterTypeDescription
$messagemixedThe message to be translated.
$domainstringThe domain of the message.
$locale?QuioteLocaleThe locale to which the message should be translated.

Returns string — The translated message.

These come from an ancestor and are documented where they are declared.

MethodDeclared inDescription
getContext()BasicTranslatorRetrieve the current application context.