oliverandrich

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:

  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
Oliver

Marked As Solved

LostKobrakai

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

oliverandrich

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

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

Other popular topics Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42716 114
New

We're in Beta

About us Mission Statement