lithium\g11n\Message::_translated PHP Method

_translated() protected static method

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.
See also: lithium\g11n\Catalog
protected static _translated ( string $id, integer $count, string $locale, array $options = [] ) : string
$id string The lookup key.
$count integer Used to determine the correct plural form.
$locale string The target locale.
$options array Passed through to `Catalog::read()`. Valid options are: - `'scope'`: The scope of the message. - `'context'`: The disambiguating context.
return string The translation or `null` if none could be found or the plural form could not be determined.
    protected static function _translated($id, $count, $locale, array $options = array())
    {
        $params = compact('id', 'count', 'locale', 'options');
        $cache =& static::$_cachedPages;
        return static::_filter(__FUNCTION__, $params, function ($self, $params) use(&$cache) {
            extract($params);
            if (isset($options['context']) && $options['context'] !== null) {
                $context = $options['context'];
                $id = "{$id}|{$context}";
            }
            if (!isset($cache[$options['scope']][$locale])) {
                $cache[$options['scope']][$locale] = Catalog::read(true, 'message', $locale, $options);
            }
            $page = $cache[$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];
            }
        });
    }