oliverandrich
Why is accept-languages not evaluated?
Hi everybody,
I spent the whole day trying to find out how i18n in Phoenix works. Or why it is working for a site like vutuv.de, while it is not working in my code. So far it did the following:
- Added configuration in my config.exs
# Configuration for gettext
config :jocasta, Jocasta.Gettext, default_locale: "en", allowed_locales: ~w(en de)
-
Created the relevant translation files with
mix gettext.extractandmix gettext.merge -
Validated that it works in general by changing the default_locale manually.
I expected that Phoenix as a frame automatically parses the Accept-Language header and sets the locale for the request. But it doesn’t seem to work like that. Now I have two questions:
- Is my expectation correct and I have just configuration error?
- Or do I have to write a plug for my project, that parses the header and calls Gettext.put_locale/1 manually?
I want to avoid using a package like set_locale that changes the URLs. I don’t like that approach and prefer to handle the Accept-Language header internally.
Best regards
Oliver
Marked As Solved
LostKobrakai
Your expectation is not correct. There are no attempts made by phoenix nor gettext to deal with accept language headers.
For an implementation of such you can look at:
https://hexdocs.pm/ex_cldr/Cldr.Plug.AcceptLanguage.html#content
Edit:
Seems like cowlib can also parse the header:
Also Liked
oliverandrich
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
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









