Skip to content

GettextTranslator

GettextTranslator defines the translator interface for gettext.

class GettextTranslator extends BasicTranslator

ExtendsBasicTranslator
Since1.0.0
SourceTranslation/GettextTranslator.php
MethodDescription
initialize(Context $context, array<string, mixed> $parameters = []): voidInitialize this Translator.
loadDomainData(string $domain): voidLoads the data from the data file for the given domain with the current locale.
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 loadDomainData(string $domain): void

Loads the data from the data file for the given domain with the current locale.

The domain to load the data for.

ParameterTypeDescription
$domainstringThe domain to load the data for.

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.

Only clears what localeChanged()/loadDomainData() derive from the current locale — context, domainPathPattern, domainPaths and the store-calls settings are configured once from initialize() parameters and never restored afterward, so clearing them here would silently break every subsequent request’s translations for the rest of the worker’s lifetime.

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.