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.extract
andmix 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