class Translator extends NamespacedItemResolver implements TranslatorInterface (View source)

Traits

Methods

array
parseKey(string $key)

Parse a key into namespace, group, and item.

void
setParsedKey(string $key, array $parsed)

Set the parsed value of a key.

static void
macro(string $name, callable $macro)

Register a custom macro.

from Macroable
static bool
hasMacro(string $name)

Checks if macro is registered.

from Macroable
static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

from Macroable
mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

from Macroable
void
__construct(LoaderInterface $loader, string $locale)

Create a new translator instance.

bool
hasForLocale(string $key, string|null $locale = null)

Determine if a translation exists for a given locale.

bool
has(string $key, string|null $locale = null, bool $fallback = true)

Determine if a translation exists.

string|array|null
get(string $key, array $replace = array(), string|null $locale = null, bool $fallback = true)

Get the translation for the given key.

void
addLines(array $lines, string $locale, string $namespace = '*')

Add translation lines to the given locale.

string
choice(string $key, int|array|Countable $number, array $replace = array(), string $locale = null)

Get a translation according to an integer value.

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

Get the translation for a given key.

string
transChoice(string $id, int|array|Countable $number, array $parameters = array(), string $domain = 'messages', string $locale = null)

Get a translation according to an integer value.

void
load(string $namespace, string $group, string $locale)

Load the specified language group.

void
addNamespace(string $namespace, string $hint)

Add a new namespace to the loader.

MessageSelector
getSelector()

Get the message selector instance.

void
setSelector(MessageSelector $selector)

Set the message selector instance.

getLoader()

Get the language line loader implementation.

string
locale()

Get the default locale being used.

string
getLocale()

Get the default locale being used.

void
setLocale(string $locale)

Set the default locale.

string
getFallback()

Get the fallback locale being used.

void
setFallback(string $fallback)

Set the fallback locale being used.

Details

at line line 308
array parseKey(string $key)

Parse a key into namespace, group, and item.

Parameters

string $key

Return Value

array

void setParsedKey(string $key, array $parsed)

Set the parsed value of a key.

Parameters

string $key
array $parsed

Return Value

void

in Macroable at line line 24
static void macro(string $name, callable $macro)

Register a custom macro.

Parameters

string $name
callable $macro

Return Value

void

in Macroable at line line 35
static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

in Macroable at line line 49
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in Macroable at line line 71
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

at line line 60
void __construct(LoaderInterface $loader, string $locale)

Create a new translator instance.

Parameters

LoaderInterface $loader
string $locale

Return Value

void

at line line 73
bool hasForLocale(string $key, string|null $locale = null)

Determine if a translation exists for a given locale.

Parameters

string $key
string|null $locale

Return Value

bool

at line line 86
bool has(string $key, string|null $locale = null, bool $fallback = true)

Determine if a translation exists.

Parameters

string $key
string|null $locale
bool $fallback

Return Value

bool

at line line 100
string|array|null get(string $key, array $replace = array(), string|null $locale = null, bool $fallback = true)

Get the translation for the given key.

Parameters

string $key
array $replace
string|null $locale
bool $fallback

Return Value

string|array|null

at line line 139
void addLines(array $lines, string $locale, string $namespace = '*')

Add translation lines to the given locale.

Parameters

array $lines
string $locale
string $namespace

Return Value

void

at line line 213
string choice(string $key, int|array|Countable $number, array $replace = array(), string $locale = null)

Get a translation according to an integer value.

Parameters

string $key
int|array|Countable $number
array $replace
string $locale

Return Value

string

at line line 235
string|array|null trans(string $id, array $parameters = array(), string $domain = 'messages', string $locale = null)

Get the translation for a given key.

Parameters

string $id
array $parameters
string $domain
string $locale

Return Value

string|array|null

at line line 250
string transChoice(string $id, int|array|Countable $number, array $parameters = array(), string $domain = 'messages', string $locale = null)

Get a translation according to an integer value.

Parameters

string $id
int|array|Countable $number
array $parameters
string $domain
string $locale

Return Value

string

at line line 263
void load(string $namespace, string $group, string $locale)

Load the specified language group.

Parameters

string $namespace
string $group
string $locale

Return Value

void

at line line 297
void addNamespace(string $namespace, string $hint)

Add a new namespace to the loader.

Parameters

string $namespace
string $hint

Return Value

void

at line line 335
MessageSelector getSelector()

Get the message selector instance.

Return Value

MessageSelector

at line line 350
void setSelector(MessageSelector $selector)

Set the message selector instance.

Parameters

MessageSelector $selector

Return Value

void

at line line 360
LoaderInterface getLoader()

Get the language line loader implementation.

Return Value

LoaderInterface

at line line 370
string locale()

Get the default locale being used.

Return Value

string

at line line 380
string getLocale()

Get the default locale being used.

Return Value

string

at line line 391
void setLocale(string $locale)

Set the default locale.

Parameters

string $locale

Return Value

void

at line line 401
string getFallback()

Get the fallback locale being used.

Return Value

string

at line line 412
void setFallback(string $fallback)

Set the fallback locale being used.

Parameters

string $fallback

Return Value

void