lithium\g11n\Message::_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.

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

string

The 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 = 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];
			}
		});
	}