Skip to content

Instantly share code, notes, and snippets.

@crisu83
Created September 1, 2013 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save crisu83/6403873 to your computer and use it in GitHub Desktop.
Save crisu83/6403873 to your computer and use it in GitHub Desktop.
<?php
/**
* Returns the active language.
* @return string the locale.
*/
public function resolveActiveLanguage()
{
$user = user();
$matches = array();
if ($user->hasState('__locale')) {
return $user->getState('__locale');
} else if (preg_match(
'/^\/([a-z]{2}(?:_[a-z]{2})?)\//i',
substr($this->request->url, strlen($this->baseUrl)),
$matches
) !== false && isset($matches[1], $this->languages[$matches[1]])
) {
return $matches[1];
} else {
return $this->defaultLanguage;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment