Symfony2 API
Class

Symfony\Bundle\FrameworkBundle\Translation\Translator

class Translator extends Translator

Translator.

Methods

__construct(ContainerInterface $container, MessageSelector $selector, array $loaderIds = array(), array $options = array())

Constructor.

addLoader(string $format, LoaderInterface $loader)

Adds a Loader.

from Translator
addResource(string $format, mixed $resource, string $locale, string $domain = 'messages')

Adds a Resource.

from Translator
setLocale(string $locale)

Sets the current locale.

from Translator
string getLocale()

Returns the current locale.

setFallbackLocale(string|array $locales)

Sets the fallback locale(s).

from Translator
string trans(string $id, array $parameters = array(), string $domain = 'messages', string $locale = null)

Translates the given message.

from Translator
string transChoice(string $id, integer $number, array $parameters = array(), string $domain = 'messages', string $locale = null)

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

from Translator

Details

at line 45
public __construct(ContainerInterface $container, MessageSelector $selector, array $loaderIds = array(), array $options = array())

Constructor.

Parameters

ContainerInterface $container A ContainerInterface instance
MessageSelector $selector The message selector for pluralization
array $loaderIds An array of loader Ids
array $options An array of options

in Translator at line 78
public addLoader(string $format, LoaderInterface $loader)

Adds a Loader.

Parameters

string $format The name of the loader (see addResource())
LoaderInterface $loader A LoaderInterface instance

in Translator at line 93
public addResource(string $format, mixed $resource, string $locale, string $domain = 'messages')

Adds a Resource.

Parameters

string $format The name of the loader (see addLoader())
mixed $resource The resource name
string $locale The locale
string $domain The domain

in Translator at line 105
public setLocale(string $locale)

Sets the current locale.

Parameters

string $locale The locale

at line 68
public string getLocale()

Returns the current locale.

Return Value

string The locale

in Translator at line 127
public setFallbackLocale(string|array $locales)

Sets the fallback locale(s).

Parameters

string|array $locales The fallback locale(s)

in Translator at line 140
public string trans(string $id, array $parameters = array(), string $domain = 'messages', string $locale = null)

Translates the given message.

Parameters

string $id The message id
array $parameters An array of parameters for the message
string $domain The domain for the message
string $locale The locale

Return Value

string The translated string

in Translator at line 158
public string transChoice(string $id, integer $number, array $parameters = array(), string $domain = 'messages', string $locale = null)

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

Parameters

string $id The message id
integer $number The number to use to find the indice of the message
array $parameters An array of parameters for the message
string $domain The domain for the message
string $locale The locale

Return Value

string The translated string