wlminimal
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
Marked As Solved
sfusato
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:
Also Liked
kip
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
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









