Translator

TranslatorInterface

Translator capable of translating statically defined messages and [Translatable]s.

Tags
author

Jakub Jabůrek jaburek.jakub@gmail.com

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
APIYes
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
APIYes
Return values
string

locale code

getLocales()

Returns all configured locales.

public getLocales() : iterable<string|int, string>
APIYes
Return values
iterable<string|int, string>

locale codes

overrideLocale()

Changes current translator locale to another one.

public overrideLocale(string $locale) : $this
APIYes
Parameters
$locale : string

new locale

Return values
$this

restoreLocale()

Undones the last call to [overrideLocale()].

public restoreLocale() : $this
APIYes

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
$this

trans()

Translates the given message.

public trans(string $id[, array<string, mixed> $parameters = [] ][, string|null $domain = null ][, string|null $locale = null ]) : string
APIYes
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
APIYes
Parameters
$string : Translatable

translatable

$locale : string|null = null

locale override

Return values
string|null

translated message or null if language variant is not defined


        
On this page

Search results