I have an Elixir / Phoenix application that reacts differently depending on the domain (aka tenant).
The tenant has a specific language, such as "fr_FR", "en_US", etc.
I want to translate the router URI depending on the current locale :
get "/classifieds/new", ClassifiedController, :new
get "/annonces/ajout", ClassifiedController, :new
So far, I thought it would be possible to do something like this (pseudo-code):
if locale() == :fr do
scope "/", Awesome.App, as: :app do
pipe_through :browser
get "/annonces/ajout", ClassifiedController, :new
end
else
scope "/", Awesome.App, as: :app do
pipe_through :browser
get "/classifieds/new", ClassifiedController, :new
end
end
This does not work, since the router was compiled during server boot, so you do not have the context of the current connection (locale, domain, host, etc.).
So far, my solution (which works) has been to create two areas with two aliases:
scope "/", Awesome.App, as: :fr_app do
pipe_through :browser
get "/annonces/ajout", ClassifiedController, :new
end
scope "/", Awesome.App, as: :app do
pipe_through :browser
get "/classifieds/new", ClassifiedController, :new
end
and associate assistant:
localized_path(conn, path, action)
(: app_classified_new_path) fr (: fr_app_classified_new_path), " fr" (). , "ru" ).
, :
"something_foo_path()" "localized_path()"
(fr, en, it, whatever), , ( , fr "fr"
locale/conn (/bugfix?) .