TranslatorInterface
in
Translator capable of translating statically defined messages and [Translatable]s.
Tags
Table of Contents
Methods
- getAsTranslatable() : Translatable
- Returns the given message as a [Translatable].
- getLocale() : string
- Returns the current translator locale.
- getLocales() : iterable<string|int, string>
- Returns all configured locales.
- overrideLocale() : $this
- Changes current translator locale to another one.
- restoreLocale() : $this
- Undones the last call to [overrideLocale()].
- trans() : string
- Translates the given message.
- transl() : string|null
- Translates the given [Translatable].
Methods
getAsTranslatable()
Returns the given message as a [Translatable].
public
getAsTranslatable(string $id[, array<string, mixed> $parameters = [] ][, string|null $domain = null ]) : Translatable
Parameters
- $id : string
-
message identifier
- $parameters : array<string, mixed> = []
-
parameters to substitute
- $domain : string|null = null
-
translation domain
Return values
Translatable —translatable message
getLocale()
Returns the current translator locale.
public
getLocale() : string
Return values
string —locale code
getLocales()
Returns all configured locales.
public
getLocales() : iterable<string|int, string>
Return values
iterable<string|int, string> —locale codes
overrideLocale()
Changes current translator locale to another one.
public
overrideLocale(string $locale) : $this
Parameters
- $locale : string
-
new locale
Return values
$thisrestoreLocale()
Undones the last call to [overrideLocale()].
public
restoreLocale() : $this
Locale overriding behaves like a stack, this method may be called multiple times to undone multiple calls to overrideLocale().
Trying to restore previous locale when no overrides are left has no effect.
Return values
$thistrans()
Translates the given message.
public
trans(string $id[, array<string, mixed> $parameters = [] ][, string|null $domain = null ][, string|null $locale = null ]) : string
Parameters
- $id : string
-
message identifier
- $parameters : array<string, mixed> = []
-
parameters to substitute
- $domain : string|null = null
-
translation domain
- $locale : string|null = null
-
locale override
Return values
string —translated message
transl()
Translates the given [Translatable].
public
transl(Translatable $string[, string|null $locale = null ]) : string|null
Parameters
- $string : Translatable
-
translatable
- $locale : string|null = null
-
locale override
Return values
string|null —translated message or null
if language variant is not defined