I suggest you choose @patnowak's answer. Use Gettext that the tool is made for translation and powerful enough.
If you still want to do this, remember render/3 in the controller calls the render/2 functions defined in the views, if defined. If not, it performs the default rendering function and looks for the template. Read the docs for more details.
So, for example, this is a controller:
def index(conn, params) do
Now define this in the view:
def render("index.html, assigns) do case assigns[:lang] do "fr" -> render("index_fr.html", assigns) _others -> render("index_en.html", assigns) end end
You can also write a plug-in that automatically puts :lang in the assignment:
def lang_plug(conn, opts) do conn |> fetch_query_params() |> (fn cn -> assign(cn, :lang, cn.query_params[:lang] || "en").() end
Take a look at Plug.Conn for documents fetch_query_params/1 and assign/3 , as well as other functions for extracting a language from other places, such as: headers or bodies.
You get the idea. In a cork, fill assigns :lang , extracts them inside your specific rendering function, and acts accordingly.
However, do not do this. Using gettext is the right way.