Thanks includebeer, but negotiateLocale don't help me in this case, for now I created my getLocale() function in BaseController.php, This allows me to partially solve the problem, I only have to solve it with the setLocale() function to be able to correctly load the language files under App/Language, but for me I think it is more difficult.
PHP Code:
protected function getLocale()
{
$defaultLocale = Config("App")->defaultLocale;
$locales = Config("App")->supportedLocales;
if (service('uri')->getTotalSegments() >= 1)
{
$locale = service('uri')->getSegment(1);
if (in_array($locale, $locales))
{
return $locale;
}
}
return $defaultLocale;
}
Maybe I could indicate in the config file some of the most used languages in my projects so that setLocale() works in most of my cases, for example ['de', 'en', 'pt', 'es', 'fr', 'it'].
In the end, however, the language and routes control is done based on the settings that I pass dynamically from the database. It's not the best but it might work.