abstractclass AbstractTranslator extendsTranslator

Properties

staticprotectedarray $singletons Translator singletons for each language.
protectedarray $messages List of custom localized messages.
protectedstring[] $directories List of custom directories that contain translation files.
protectedbool $initializing Set to true while constructing.
protectedstring[] $aliases List of locales aliases.

Methods

get(string|null$locale =null)

Return a singleton instance of Translator.

__construct($locale,MessageFormatterInterface$formatter =null,$cacheDir =null,$debug =false)

No description

array
getDirectories()

Returns the list of directories translation files are searched in.

$this
setDirectories(array$directories)

Set list of directories translation files are searched in.

$this
addDirectory(string$directory)

Add a directory to the list translation files are searched in.

$this
removeDirectory(string$directory)

Remove a directory from the list translation files are searched in.

bool
resetMessages(string|null$locale =null)

Reset messages of a locale (all locale if no locale passed).

array
getLocalesFiles(string$prefix ='')

Returns the list of files matching a given locale prefix (or all if empty).

array
getAvailableLocales(string$prefix ='')

Returns the list of internally available locales and already loaded custom locales.

translate(string|null$id,array$parameters =[],string|null$domain =null,string|null$locale =null)

No description

bool
loadMessagesFromFile(string$locale)

Init messages language from matching file in Lang directory.

$this
setMessages(string$locale,array$messages)

Set messages of a locale and take file first if present.

$this
setTranslations(array$messages)

Set messages of the current locale and take file first if present.

array
getMessages(string|null$locale =null)

Get messages of a locale, if none given, return all the languages.

bool
setLocale(string$locale)

Set the current translator locale and indicate if the source locale file exists

array
__debugInfo()

Show locale on var_dump().

Details

at line68
staticAbstractTranslator get(string|null$locale =null)

Return a singleton instance of Translator.

Parameters

string|null $locale optional initial locale ("en" - english by default)

Return Value

AbstractTranslator

at line80
__construct($locale,MessageFormatterInterface$formatter =null,$cacheDir =null,$debug =false)

Parameters

$locale
MessageFormatterInterface $formatter
$cacheDir
$debug

at line95
array getDirectories()

Returns the list of directories translation files are searched in.

Return Value

array

at line107
$this setDirectories(array$directories)

Set list of directories translation files are searched in.

Parameters

array $directories new directories list

Return Value

$this

at line121
$this addDirectory(string$directory)

Add a directory to the list translation files are searched in.

Parameters

string $directory new directory

Return Value

$this

at line135
$this removeDirectory(string$directory)

Remove a directory from the list translation files are searched in.

Parameters

string $directory directory path

Return Value

$this

at line153
bool resetMessages(string|null$locale =null)

Reset messages of a locale (all locale if no locale passed).

Remove custom messages and reload initial messages from matching file in Lang directory.

Parameters

string|null $locale

Return Value

bool

at line182
array getLocalesFiles(string$prefix ='')

Returns the list of files matching a given locale prefix (or all if empty).

Parameters

string $prefix prefix required to filter result

Return Value

array

at line205
array getAvailableLocales(string$prefix ='')

Returns the list of internally available locales and already loaded custom locales.

(It will ignore custom translator dynamic loading.)

Parameters

string $prefix prefix required to filter result

Return Value

array

at line215
protected translate(string|null$id,array$parameters =[],string|null$domain =null,string|null$locale =null)

Parameters

string|null $id
array $parameters
string|null $domain
string|null $locale

at line251
protectedbool loadMessagesFromFile(string$locale)

Init messages language from matching file in Lang directory.

Parameters

string $locale

Return Value

bool

at line264
$this setMessages(string$locale,array$messages)

Set messages of a locale and take file first if present.

Parameters

string $locale
array $messages

Return Value

$this

at line283
$this setTranslations(array$messages)

Set messages of the current locale and take file first if present.

Parameters

array $messages

Return Value

$this

at line296
array getMessages(string|null$locale =null)

Get messages of a locale, if none given, return all the languages.

Parameters

string|null $locale

Return Value

array

at line308
bool setLocale(string$locale)

Set the current translator locale and indicate if the source locale file exists

Parameters

string $locale locale ex. en

Return Value

bool

at line372
array __debugInfo()

Show locale on var_dump().

Return Value

array