Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to use the accept-languages header to redirect to a locale instead of the config file? #24

Open
mathiasHillmann opened this issue Sep 4, 2021 · 0 comments

Comments

@mathiasHillmann
Copy link

mathiasHillmann commented Sep 4, 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 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.

@mathiasHillmann 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant