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 @@
-<%= get_flash(@conn, :info) %>
<%= get_flash(@conn, :error) %>
Real-time communication for the Kolab groupware system.
+<%= gettext "Real-time communication for the Kolab groupware system." %>