I'm developing a multilingual application using the Phoenix Framework
So far, the router look like this:
scope "/:locale", App do
pipe_through [:browser, :browser_session]
get "/", PageController, :index
get "/otherpage", OtherpageController, :index
end
scope "/", App do
end
I used the plug in the docs : http://www.phoenixframework.org/docs/understanding-plug#section-module-plugs
And to make the "locale" persistent in the app, I used the custom action in the Phoenix.Controller module to do this:
def action(conn, _) do
apply(__MODULE__, action_name(conn), [conn,
conn.params,
conn.assigns.locale])
end
so now every time I generated a controller I should add the above custom action, and change every action in the new controller to inject the locale
def index(conn, _params, locale) do
list = Repo.all(List)
render conn, "index.html", list: list
end
There are two things that I'm struggling with:
1 - Is this the right way ? or I'm messing something ?
2 - And how to make the scope "/" to be redirect to scope "/:locale" with a default value like: "en" ?
EDIT
I like to have this url: "example.com/en"
Kayne