lithium\g11n\Message::_translated()
Retrieves translations through the Catalog
class by using $id
as the lookup
key and taking the current or - if specified - the provided locale as well as the
scope into account. Hereupon the correct plural form is determined by passing the
value of the 'count'
option to a closure.
Parameters
-
string
$id
The lookup key.
-
integer
$count
Used to determine the correct plural form.
-
string
$locale
The target locale.
-
array
$options
Passed through to
Catalog::read()
. Valid options are:'scope'
: The scope of the message.'context'
: The disambiguating context.
Returns
stringThe translation or null
if none could be found or the plural
form could not be determined.
Filter
This method can be filtered.
Source
protected static function _translated($id, $count, $locale, array $options = []) {
$params = compact('id', 'count', 'locale', 'options');
return Filters::run(get_called_class(), __FUNCTION__, $params, function($params) {
extract($params);
if (isset($options['context']) && $options['context'] !== null) {
$context = $options['context'];
$id = "{$id}|{$context}";
}
if (!isset(static::$_cachedPages[$options['scope']][$locale])) {
static::$_cachedPages[$options['scope']][$locale] = Catalog::read(
true, 'message', $locale, $options
);
}
$page = static::$_cachedPages[$options['scope']][$locale];
if (!isset($page[$id])) {
return null;
}
if (!is_array($page[$id])) {
return $page[$id];
}
if (!isset($page['pluralRule']) || !is_callable($page['pluralRule'])) {
return null;
}
$key = $page['pluralRule']($count);
if (isset($page[$id][$key])) {
return $page[$id][$key];
}
});
}