Gigitsu

Gigitsu

Phoenix VerifiedRoutes and routes localization

I was reading the Localized routes and path prefixes section of the Phoenix.VerifiedRoutes and I found this line:

In this case, you would have a plug that looks at the host and at HTTP headers and calls Gettext.get_locale/1 accordingly.

It’s not clear to me how this plug should be used.

What I’m trying to achieve is localized routes based on the language, for example:

  • /login for English

  • /accedi for Italian

but without maintaining multiple routers.

Ideally, I would like to define the route once, with all the routes in english, and have the URL automatically translated depending on the locale or domain.

Is this possible with a plug?
Perhaps something like a reverse route translation mechanism?

I also would like to avoid external dependencies.

Marked As Solved

LostKobrakai

LostKobrakai

That line is for the case of using the hostname to distinguish between languages - not doing so by path. The text following that paragraph is for when you want to use a path segment to determine the language.

Also Liked

BartOtten

BartOtten

This is the origin feature of Routex - build powerful Phoenix routes: localize, customize, and innovate

Last Post!

Gigitsu

Gigitsu

I was hoping for a built-in solution, since I try to keep dependencies to a minimum whenever possible.

I’m familiar with Routex and have been looking through its source code. I like it a lot, but it feels a bit overcomplicated for my current needs. That said, I’m still evaluating my requirements, so I’m not ruling it out for my project.

Where Next?

Popular in Questions Top

RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
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
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

We're in Beta

About us Mission Statement