Translator
class Translator extends NamespacedItemResolver implements Translator
Traits
Properties
protected array | $parsed | A cache of the parsed items. |
from NamespacedItemResolver |
static protected array | $macros | The registered string macros. |
from Macroable |
protected LoaderInterface | $loader | The loader implementation. |
|
protected string | $locale | The default locale being used by the translator. |
|
protected string | $fallback | The fallback locale used by the translator. |
|
protected array | $loaded | The array of loaded translation groups. |
|
protected MessageSelector | $selector | The message selector. |
Methods
Parse a key into namespace, group, and item.
Parse an array of basic segments.
Parse an array of namespaced segments.
Set the parsed value of a key.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Determine if a translation exists for a given locale.
Determine if a translation exists.
Get the translation for a given key.
Get the translation for the given key.
Get the translation for a given key from the JSON translation files.
Get a translation according to an integer value.
Get the proper locale for a choice operation.
Retrieve a language line out the loaded array.
Make the place-holder replacements on a line.
Sort the replacements array.
Add translation lines to the given locale.
Load the specified language group.
Determine if the given group has been loaded.
Add a new namespace to the loader.
Get the array of locales to be checked.
Get the message selector instance.
Get the language line loader implementation.
Get the default locale being used.
Get the default locale being used.
Set the default locale.
Get the fallback locale being used.
Set the fallback locale being used.
Details
at line 360
array
parseKey(string $key)
Parse a key into namespace, group, and item.
in
NamespacedItemResolver at line 52
protected array
parseBasicSegments(array $segments)
Parse an array of basic segments.
in
NamespacedItemResolver at line 79
protected array
parseNamespacedSegments(string $key)
Parse an array of namespaced segments.
in
NamespacedItemResolver at line 102
void
setParsedKey(string $key, array $parsed)
Set the parsed value of a key.
in
Macroable at line 24
static void
macro(string $name, callable $macro)
Register a custom macro.
in
Macroable at line 35
static bool
hasMacro(string $name)
Checks if macro is registered.
in
Macroable at line 49
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 71
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
at line 59
void
__construct(LoaderInterface $loader, string $locale)
Create a new translator instance.
at line 72
bool
hasForLocale(string $key, string|null $locale = null)
Determine if a translation exists for a given locale.
at line 85
bool
has(string $key, string|null $locale = null, bool $fallback = true)
Determine if a translation exists.
at line 98
mixed
trans(string $key, array $replace = [], string $locale = null)
Get the translation for a given key.
at line 112
string|array|null
get(string $key, array $replace = [], string|null $locale = null, bool $fallback = true)
Get the translation for the given key.
at line 148
string
getFromJson(string $key, array $replace = [], string $locale = null)
Get the translation for a given key from the JSON translation files.
at line 183
string
transChoice(string $key, int|array|Countable $number, array $replace = [], string $locale = null)
Get a translation according to an integer value.
at line 197
string
choice(string $key, int|array|Countable $number, array $replace = [], string $locale = null)
Get a translation according to an integer value.
at line 223
protected string
localeForChoice(string|null $locale)
Get the proper locale for a choice operation.
at line 238
protected string|array|null
getLine(string $namespace, string $group, string $locale, string $item, array $replace)
Retrieve a language line out the loaded array.
at line 258
protected string
makeReplacements(string $line, array $replace)
Make the place-holder replacements on a line.
at line 283
protected array
sortReplacements(array $replace)
Sort the replacements array.
at line 298
void
addLines(array $lines, string $locale, string $namespace = '*')
Add translation lines to the given locale.
at line 315
void
load(string $namespace, string $group, string $locale)
Load the specified language group.
at line 337
protected bool
isLoaded(string $namespace, string $group, string $locale)
Determine if the given group has been loaded.
at line 349
void
addNamespace(string $namespace, string $hint)
Add a new namespace to the loader.
at line 377
protected array
localeArray(string|null $locale)
Get the array of locales to be checked.
at line 387
MessageSelector
getSelector()
Get the message selector instance.
at line 402
void
setSelector(MessageSelector $selector)
Set the message selector instance.
at line 412
LoaderInterface
getLoader()
Get the language line loader implementation.
at line 422
string
locale()
Get the default locale being used.
at line 432
string
getLocale()
Get the default locale being used.
at line 443
void
setLocale(string $locale)
Set the default locale.
at line 453
string
getFallback()
Get the fallback locale being used.
at line 464
void
setFallback(string $fallback)
Set the fallback locale being used.