Translator
class Translator extends NamespacedItemResolver implements TranslatorInterface (View source)
Properties
protected array | $parsed | A cache of the parsed items. |
from NamespacedItemResolver |
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. |
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.
Determine if a translation exists.
Get the translation for the given key.
Retrieve a language line out the loaded array.
Make the place-holder replacements on a line.
Sort the replacements array.
Get a translation according to an integer value.
Get the translation for a given key.
Get a translation according to an integer value.
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.
Set 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
array
parseKey(string $key)
Parse a key into namespace, group, and item.
protected array
parseBasicSegments(array $segments)
Parse an array of basic segments.
protected array
parseNamespacedSegments(string $key)
Parse an array of namespaced segments.
void
setParsedKey(string $key, array $parsed)
Set the parsed value of a key.
void
__construct(LoaderInterface $loader, string $locale)
Create a new translator instance.
bool
has(string $key, string $locale = null)
Determine if a translation exists.
string
get(string $key, array $replace = array(), string $locale = null)
Get the translation for the given key.
protected string|null
getLine(string $namespace, string $group, string $locale, string $item, array $replace)
Retrieve a language line out the loaded array.
protected string
makeReplacements(string $line, array $replace)
Make the place-holder replacements on a line.
protected array
sortReplacements(array $replace)
Sort the replacements array.
string
choice(string $key, int $number, array $replace = array(), string $locale = null)
Get a translation according to an integer value.
string
trans(string $id, array $parameters = array(), string $domain = 'messages', string $locale = null)
Get the translation for a given key.
string
transChoice(string $id, int $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.
protected bool
isLoaded(string $namespace, string $group, string $locale)
Determine if the given group has been loaded.
void
addNamespace(string $namespace, string $hint)
Add a new namespace to the loader.
protected array
parseLocale(string|null $locale)
Get the array of locales to be checked.
MessageSelector
getSelector()
Get the message selector instance.
void
setSelector(MessageSelector $selector)
Set the message selector instance.
LoaderInterface
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.