Documentation

TranslatorInterface

TranslatorInterface.

Tags
author

Fabien Potencier fabien@symfony.com

Table of Contents

getLocale()  : string
Returns the current locale.
setLocale()  : mixed
Sets the current locale.
trans()  : string
Translates the given message.
transChoice()  : string
Translates the given choice message by choosing a translation according to a number.

Methods

getLocale()

Returns the current locale.

public getLocale() : string
Return values
string —

The locale

setLocale()

Sets the current locale.

public setLocale(string $locale) : mixed
Parameters
$locale : string

The locale

Tags
throws
InvalidArgumentException

If the locale contains invalid characters

Return values
mixed —

trans()

Translates the given message.

public trans(string $id[, array<string|int, mixed> $parameters = [] ][, string|null $domain = null ][, string|null $locale = null ]) : string
Parameters
$id : string

The message id (may also be an object that can be cast to string)

$parameters : array<string|int, mixed> = []

An array of parameters for the message

$domain : string|null = null

The domain for the message or null to use the default

$locale : string|null = null

The locale or null to use the default

Tags
throws
InvalidArgumentException

If the locale contains invalid characters

Return values
string —

The translated string

transChoice()

Translates the given choice message by choosing a translation according to a number.

public transChoice(string $id, int $number[, array<string|int, mixed> $parameters = [] ][, string|null $domain = null ][, string|null $locale = null ]) : string
Parameters
$id : string

The message id (may also be an object that can be cast to string)

$number : int

The number to use to find the index of the message

$parameters : array<string|int, mixed> = []

An array of parameters for the message

$domain : string|null = null

The domain for the message or null to use the default

$locale : string|null = null

The locale or null to use the default

Tags
throws
InvalidArgumentException

If the locale contains invalid characters

Return values
string —

The translated string

Search results