You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On the initial redirect of the url / currently the MultiLang middleware uses the first segment as the locale or uses the fallback in the config file as the locale. Would it be possible try to use the accept-languages header first instead of going to fall back right away?
Something like (Ps: this is untested code):
$acceptLanguages = explode(';', $request->header('accept-languages');
$locale = null;
foreach($acceptLanguages as $lang) {
if(in_array($lang, array_keys(config('multilang.locales')))) {
$locale = $lang;
break;
}
}
// More code that sets the locale segment on the url and whatnot using the locale above
Between lines 271 and 272 of Multilang.php would make this a possibility I think.
Of course this could make a Denial of Service attack possible if someone passes a really long accept-languages header, so there is a need to check its length of something like that, but I belive this is better than just using the default locale on the config file.
The text was updated successfully, but these errors were encountered:
mathiasHillmann
changed the title
Is it possible to use the accept-language header to redirect to a locale instead of the config file?
Is it possible to use the accept-languages header to redirect to a locale instead of the config file?
Sep 5, 2021
On the initial redirect of the url
/
currently the MultiLang middleware uses the first segment as the locale or uses the fallback in the config file as the locale. Would it be possible try to use theaccept-languages
header first instead of going to fall back right away?Something like (Ps: this is untested code):
Between lines 271 and 272 of Multilang.php would make this a possibility I think.
Of course this could make a Denial of Service attack possible if someone passes a really long
accept-languages
header, so there is a need to check its length of something like that, but I belive this is better than just using the default locale on the config file.The text was updated successfully, but these errors were encountered: