How to get a users' locale info then change locale in phoenix

Hi
I want to display my web app in different language depends on users’ browser language.
I googled it for how to get a users’ locale then says " The proper way is to look at the HTTP [Accept-Language] header sent to the server."

1.How can I get this info in phoenix?
then
2. How can I apply this info into phoenix so change default locale?
(maybe using Gettext.put_locale?)

Thanks

This tutorial shows you line by line how to write your own plug instead of using something like set_locale:

So, we are going to create our own custom plug called simply Locale . Its behaviour will be somewhat similar to the set_locale plug used in the previous article, but with some differences. Here are the key points:

3 Likes

If you’re working on i18n and l10n then you might also find ex_cldr useful (I am the author). In it you will find a parser to the Accept-Language header, a parser for language tags (locale string) and a means to set locale for both Gettext and Cldr. See the docs for plugs

3 Likes