lithium\g11n\Locale::preferred()

public static method

Determines the preferred locale from a request or array. Optionally negotiates the preferred locale with available locales.

Parameters

  • object|array $request

    An action or console request object or an array of locales.

  • array $available

    A list of locales to negotiate the preferred locale with.

Returns

string

The preferred locale in its canonical form (i.e. 'fr_CA').

Source

	public static function preferred($request, $available = null) {
		if (is_array($request)) {
			$result = $request;
		} elseif ($request instanceof ActionRequest) {
			$result = static::_preferredAction($request);
		} elseif ($request instanceof ConsoleRequest) {
			$result = static::_preferredConsole($request);
		} else {
			return null;
		}
		if (!$available) {
			return array_shift($result);
		}
		foreach ((array) $result as $locale) {
			if ($match = static::lookup($available, $locale)) {
				return $match;
			}
		}
	}