lithium\g11n\Locale::_preferredConsole()

protected static method

Detects preferred locales from a console request by looking at certain environment variables. The environment variables may be present or not depending on your system. If multiple variables are present the following hierarchy is used: 'LANGUAGE', 'LC_ALL', 'LANG'.

The locales of the 'LC_ALL' and the 'LANG' are formatted according to the posix standard: language(_territory)(.encoding)(@modifier). Locales having such a format are automatically canonicalized and transformed into the Locale class' format.

Parameters

  • \lithium\console\Request $request

Returns

array

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

Source

	protected static function _preferredConsole($request) {
		$regex = '(?P<locale>[\w\_]+)(\.|@|$)+';
		$result = [];

		if ($value = $request->env('LANGUAGE')) {
			return explode(':', $value);
		}
		foreach (['LC_ALL', 'LANG'] as $variable) {
			$value = $request->env($variable);

			if (!$value || $value === 'C' || $value === 'POSIX') {
				continue;
			}
			if (preg_match("/{$regex}/", $value, $matches)) {
				return (array) $matches['locale'];
			}
		}
		return $result;
	}