lithium\g11n\Locale::_preferredAction()

protected static method

Detects preferred locales from an action request by looking at the 'Accept-Language' header as described by RFC 2616, section 14.4.

Parameters

  • \lithium\action\Request $request

Returns

array

Preferred locales in their canonical form (i.e. 'fr_CA').

Source

	protected static function _preferredAction($request) {
		$result = [];
		$regex  = "/^\s*(?P<locale>\w\w(?:[-]\w\w)?)(?:;q=(?P<quality>(0|1|0\.\d+)))?\s*$/";

		foreach (explode(',', $request->env('HTTP_ACCEPT_LANGUAGE')) as $part) {
			if (preg_match($regex, $part, $matches)) {
				$locale = static::canonicalize($matches['locale']);
				$quality = isset($matches['quality']) ? $matches['quality'] : 1;
				$result[$quality][] = $locale;
			}
		}
		krsort($result);

		return array_reduce($result, function($carry, $item) {
			return array_merge($carry, array_values($item));
		}, []);
	}