diff --git a/lib/kolab_chat/locale.ex b/lib/kolab_chat/locale.ex new file mode 100644 index 0000000..fa91775 --- /dev/null +++ b/lib/kolab_chat/locale.ex @@ -0,0 +1,15 @@ +defmodule KolabChat.Locale do + import Plug.Conn + + def init(opts), do: opts + + def call(conn, _opts) do + case conn.params["locale"] || get_session(conn, :locale) do + nil -> + conn + locale -> + Gettext.put_locale(MyApp.Gettext, locale) + put_session(conn, :locale, locale) + end + end +end diff --git a/web/router.ex b/web/router.ex index 52bcbac..9a3c158 100644 --- a/web/router.ex +++ b/web/router.ex @@ -1,26 +1,27 @@ defmodule KolabChat.Router do use KolabChat.Web, :router pipeline :browser do plug :accepts, ["html"] plug :fetch_session plug :fetch_flash plug :protect_from_forgery plug :put_secure_browser_headers + plug KolabChat.Locale end pipeline :api do plug :accepts, ["json"] end scope "/", KolabChat do pipe_through :browser # Use the default browser stack get "/", PageController, :index end # Other scopes may use custom stacks. # scope "/api", KolabChat do # pipe_through :api # end end diff --git a/web/templates/layout/app.html.eex b/web/templates/layout/app.html.eex index 1ca3b75..89b00d3 100644 --- a/web/templates/layout/app.html.eex +++ b/web/templates/layout/app.html.eex @@ -1,35 +1,35 @@ <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="description" content=""> <meta name="author" content=""> - <title>Kolab Real Time Communication</title> + <title><%= gettext "Kolab Real Time Communication" %></title> <link rel="stylesheet" href="<%= static_path(@conn, "/css/app.css") %>"> </head> <body> <div class="container"> <header class="header"> <nav role="navigation"> <ul class="nav nav-pills pull-right"> - <li><a href="/login">Login</a></li> + <li><a href="/login"><%= gettext "Login" %></a></li> </ul> </nav> <span class="logo"></span> </header> <p class="alert alert-info" role="alert"><%= get_flash(@conn, :info) %></p> <p class="alert alert-danger" role="alert"><%= get_flash(@conn, :error) %></p> <main role="main"> <%= render @view_module, @view_template, assigns %> </main> </div> <!-- /container --> <script src="<%= static_path(@conn, "/js/app.js") %>"></script> </body> </html> diff --git a/web/templates/page/index.html.eex b/web/templates/page/index.html.eex index 8e96e32..ba251e4 100644 --- a/web/templates/page/index.html.eex +++ b/web/templates/page/index.html.eex @@ -1,5 +1,4 @@ <div class="jumbotron"> <h2><%= gettext "Welcome to %{name}", name: "Kolab Chat!" %></h2> - <p class="lead">Real-time communication for the Kolab groupware system.</p> + <p class="lead"><%= gettext "Real-time communication for the Kolab groupware system." %></p> </div> -