Pionia Core

Translator extends LazyTranslator
in package

Table of Contents

Constants

REGION_CODE_LENGTH  = 2

Properties

$aliases  : array<string, string>
List of locales aliases.
$directories  : array<string|int, string>
List of custom directories that contain translation files.
$initializing  : bool
Set to true while constructing.
$messages  : array<string|int, mixed>
List of custom localized messages.
$singletons  : array<string|int, mixed>
Translator singletons for each language.

Methods

__construct()  : mixed
__debugInfo()  : array<string|int, mixed>
Show locale on var_dump().
__serialize()  : array<string|int, mixed>
__unserialize()  : void
addDirectory()  : $this
Add a directory to the list translation files are searched in.
get()  : static
Return a singleton instance of Translator.
getAvailableLocales()  : array<string|int, mixed>
Returns the list of internally available locales and already loaded custom locales.
getDirectories()  : array<string|int, mixed>
Returns the list of directories translation files are searched in.
getLocalesFiles()  : array<string|int, mixed>
Returns the list of files matching a given locale prefix (or all if empty).
getMessages()  : array<string|int, mixed>
Get messages of a locale, if none given, return all the languages.
removeDirectory()  : $this
Remove a directory from the list translation files are searched in.
resetMessages()  : bool
Reset messages of a locale (all locale if no locale passed).
setDirectories()  : $this
Set list of directories translation files are searched in.
setLocale()  : void
Set the current translator locale and indicate if the source locale file exists
setMessages()  : $this
Set messages of a locale and take file first if present.
setTranslations()  : $this
Set messages of the current locale and take file first if present.
trans()  : string
Returns the translation.
loadMessagesFromFile()  : bool
Init messages language from matching file in Lang directory.
translate()  : string
compareChunkLists()  : mixed
initialize()  : void

Constants

Properties

$aliases

List of locales aliases.

protected array<string, string> $aliases = ['me' => 'sr_Latn_ME', 'scr' => 'sh']

$directories

List of custom directories that contain translation files.

protected array<string|int, string> $directories = []

$initializing

Set to true while constructing.

protected bool $initializing = false

$messages

List of custom localized messages.

protected array<string|int, mixed> $messages = []

$singletons

Translator singletons for each language.

protected static array<string|int, mixed> $singletons = []

Methods

__construct()

public __construct(mixed $locale[, MessageFormatterInterface|null $formatter = null ][, mixed $cacheDir = null ][, mixed $debug = false ]) : mixed
Parameters
$locale : mixed
$formatter : MessageFormatterInterface|null = null
$cacheDir : mixed = null
$debug : mixed = false

__debugInfo()

Show locale on var_dump().

public __debugInfo() : array<string|int, mixed>
Return values
array<string|int, mixed>

__serialize()

public __serialize() : array<string|int, mixed>
Return values
array<string|int, mixed>

__unserialize()

public __unserialize(array<string|int, mixed> $data) : void
Parameters
$data : array<string|int, mixed>

addDirectory()

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

public addDirectory(string $directory) : $this
Parameters
$directory : string

new directory

Return values
$this

get()

Return a singleton instance of Translator.

public static get([string|null $locale = null ]) : static
Parameters
$locale : string|null = null

optional initial locale ("en" - english by default)

Return values
static

getAvailableLocales()

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

public getAvailableLocales([string $prefix = '' ]) : array<string|int, mixed>

(It will ignore custom translator dynamic loading.)

Parameters
$prefix : string = ''

prefix required to filter result

Return values
array<string|int, mixed>

getDirectories()

Returns the list of directories translation files are searched in.

public getDirectories() : array<string|int, mixed>
Return values
array<string|int, mixed>

getLocalesFiles()

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

public getLocalesFiles([string $prefix = '' ]) : array<string|int, mixed>
Parameters
$prefix : string = ''

prefix required to filter result

Return values
array<string|int, mixed>

getMessages()

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

public getMessages([string|null $locale = null ]) : array<string|int, mixed>
Parameters
$locale : string|null = null
Return values
array<string|int, mixed>

removeDirectory()

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

public removeDirectory(string $directory) : $this
Parameters
$directory : string

directory path

Return values
$this

resetMessages()

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

public resetMessages([string|null $locale = null ]) : bool

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

Parameters
$locale : string|null = null
Return values
bool

setDirectories()

Set list of directories translation files are searched in.

public setDirectories(array<string|int, mixed> $directories) : $this
Parameters
$directories : array<string|int, mixed>

new directories list

Return values
$this

setLocale()

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

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

locale ex. en

setMessages()

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

public setMessages(string $locale, array<string|int, mixed> $messages) : $this
Parameters
$locale : string
$messages : array<string|int, mixed>
Return values
$this

setTranslations()

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

public setTranslations(array<string|int, mixed> $messages) : $this
Parameters
$messages : array<string|int, mixed>
Return values
$this

trans()

Returns the translation.

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

loadMessagesFromFile()

Init messages language from matching file in Lang directory.

protected loadMessagesFromFile(string $locale) : bool
Parameters
$locale : string
Return values
bool

translate()

protected translate(string|null $id[, array<string|int, mixed> $parameters = [] ][, string|null $domain = null ][, string|null $locale = null ]) : string
Parameters
$id : string|null
$parameters : array<string|int, mixed> = []
$domain : string|null = null
$locale : string|null = null
Return values
string

compareChunkLists()

private static compareChunkLists(mixed $referenceChunks, mixed $chunks) : mixed
Parameters
$referenceChunks : mixed
$chunks : mixed

initialize()

private initialize(mixed $locale[, MessageFormatterInterface|null $formatter = null ][, mixed $cacheDir = null ][, mixed $debug = false ]) : void
Parameters
$locale : mixed
$formatter : MessageFormatterInterface|null = null
$cacheDir : mixed = null
$debug : mixed = false

        
On this page

Search results