GettextTranslator
GettextTranslator defines the translator interface for gettext.
Synopsis
Section titled “Synopsis”class GettextTranslator extends BasicTranslator
| Extends | BasicTranslator |
| Since | 1.0.0 |
| Source | Translation/GettextTranslator.php |
Methods
Section titled “Methods”| Method | Description |
|---|---|
initialize(Context $context, array<string, mixed> $parameters = []): void | Initialize this Translator. |
loadDomainData(string $domain): void | Loads the data from the data file for the given domain with the current locale. |
localeChanged(QuioteLocale $newLocale): mixed | This method gets called by the translation manager when the default locale has been changed. |
reset(): void | Reset per-request locale state for worker compatibility. |
translate(mixed $message, string $domain, ?QuioteLocale $locale = null): string | Translates a message into the defined language. |
initialize()
Section titled “initialize()”public function initialize(Context $context, array<string, mixed> $parameters = []): void
Initialize this Translator.
An associative array of initialization parameters
| Parameter | Type | Description |
|---|---|---|
$context | Context | The current application context. |
$parameters | array``<``string``, ``mixed``> | An associative array of initialization parameters |
loadDomainData()
Section titled “loadDomainData()”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.
| Parameter | Type | Description |
|---|---|---|
$domain | string | The domain to load the data for. |
localeChanged()
Section titled “localeChanged()”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.
| Parameter | Type | Description |
|---|---|---|
$newLocale | QuioteLocale | The new default locale. |
Returns mixed
reset()
Section titled “reset()”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.
translate()
Section titled “translate()”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.
| Parameter | Type | Description |
|---|---|---|
$message | mixed | The message to be translated. |
$domain | string | The domain of the message. |
$locale | ?QuioteLocale | The locale to which the message should be translated. |
Returns string — The translated message.
Inherited methods
Section titled “Inherited methods”These come from an ancestor and are documented where they are declared.
| Method | Declared in | Description |
|---|---|---|
getContext() | BasicTranslator | Retrieve the current application context. |