public function setLocale($locale = null)
{
if (empty($locale) || !is_string($locale)) {
// If the locale has not been passed through the function
// it tries to get it from the first segment of the url
$locale = $this->request()->segment(1);
}
if ($this->isSupportedLocale($locale)) {
$this->setCurrentLocale($locale);
} else {
// if the first segment/locale passed is not valid the system would ask which locale have to take
// it could be taken by the browser depending on your configuration
$locale = null;
$this->getCurrentOrDefaultLocale();
}
$this->app->setLocale($this->getCurrentLocale());
$this->updateRegional();
return $locale;
}