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 (!empty($this->supportedLocales[$locale])) {
$this->currentLocale = $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;
// if we reached this point and hideDefaultLocaleInURL is true
// we have to assume we are routing to a defaultLocale route.
if ($this->hideDefaultLocaleInURL()) {
$this->currentLocale = $this->defaultLocale;
} else {
$this->currentLocale = $this->getCurrentLocale();
}
}
$this->app->setLocale($this->currentLocale);
// Regional locale such as de_DE, so formatLocalized works in Carbon
$regional = $this->getCurrentLocaleRegional();
if ($regional) {
setlocale(LC_TIME, $regional . '.UTF-8');
setlocale(LC_MONETARY, $regional . '.UTF-8');
}
return $locale;
}