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:

  1. Added configuration in my config.exs
# Configuration for gettext
config :jocasta, Jocasta.Gettext, default_locale: "en", allowed_locales: ~w(en de)
  1. Created the relevant translation files with mix gettext.extract and mix gettext.merge

  2. 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:

  1. Is my expectation correct and I have just configuration error?
  2. 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

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:


Seems like cowlib can also parse the header:


Thanks for the clarification. This makes totally clear, why I wasn’t successful today.

1 Like