Page MenuHomePhorge

D327.1775553262.diff
No OneTemporary

Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None

D327.1775553262.diff

diff --git a/Makefile b/Makefile
new file mode 100644
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,5 @@
+
+
+locale:
+ mix gettext.extract
+ mix gettext.merge priv/gettext
diff --git a/lib/kolab_chat/locale.ex b/lib/kolab_chat/locale.ex
new file mode 100644
--- /dev/null
+++ b/lib/kolab_chat/locale.ex
@@ -0,0 +1,38 @@
+defmodule KolabChat.Locale do
+ import Plug.Conn
+
+ def init(opts), do: opts
+
+ def call(conn, _opts) do
+ case get_session(conn, :locale) || client_locale(conn) do
+ nil ->
+ conn
+ locale ->
+ Gettext.put_locale(KolabChat.Gettext, locale)
+ put_session(conn, :locale, locale)
+ end
+ end
+
+ # Gets supported locale code from the client
+ # Uses 'locale' parameter or Accept-Language header
+ defp client_locale(conn) do
+ supported = Gettext.known_locales(KolabChat.Gettext)
+ locale = conn.params["locale"] || get_req_header(conn, "accept-language")
+
+ locale
+ |> to_string()
+ |> String.split(",")
+ |> Enum.map(&parse_locale/1)
+ |> Enum.filter(fn(x) -> Enum.member?(supported, x) end)
+ |> Enum.at(0)
+ end
+
+ # Extracts locale code from an element of Accept-Language header
+ defp parse_locale(locale) do
+ locale
+ |> String.split(";")
+ |> Enum.at(0)
+ |> String.trim()
+ |> String.replace("-", "_")
+ end
+end
diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot
new file mode 100644
--- /dev/null
+++ b/priv/gettext/default.pot
@@ -0,0 +1,28 @@
+## This file is a PO Template file.
+##
+## `msgid`s here are often extracted from source code.
+## Add new translations manually only if they're dynamic
+## translations that can't be statically extracted.
+##
+## Run `mix gettext.extract` to bring this file up to
+## date. Leave `msgstr`s empty as changing them here as no
+## effect: edit them in PO (`.po`) files instead.
+msgid ""
+msgstr ""
+"Language: INSERT LANGUAGE HERE\n"
+
+#: web/templates/layout/app.html.eex:10
+msgid "Kolab Real Time Communication"
+msgstr ""
+
+#: web/templates/layout/app.html.eex:19
+msgid "Login"
+msgstr ""
+
+#: web/templates/page/index.html.eex:3
+msgid "Real-time communication for the Kolab groupware system."
+msgstr ""
+
+#: web/templates/page/index.html.eex:2
+msgid "Welcome to %{name}"
+msgstr ""
diff --git a/priv/gettext/errors.pot b/priv/gettext/errors.pot
--- a/priv/gettext/errors.pot
+++ b/priv/gettext/errors.pot
@@ -7,7 +7,6 @@
## Run `mix gettext.extract` to bring this file up to
## date. Leave `msgstr`s empty as changing them here as no
## effect: edit them in PO (`.po`) files instead.
-
## From Ecto.Changeset.cast/4
msgid "can't be blank"
msgstr ""
diff --git a/web/router.ex b/web/router.ex
--- a/web/router.ex
+++ b/web/router.ex
@@ -7,6 +7,7 @@
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
+ plug KolabChat.Locale
end
pipeline :api do
diff --git a/web/templates/layout/app.html.eex b/web/templates/layout/app.html.eex
--- a/web/templates/layout/app.html.eex
+++ b/web/templates/layout/app.html.eex
@@ -7,7 +7,7 @@
<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>
@@ -16,7 +16,7 @@
<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>
diff --git a/web/templates/page/index.html.eex b/web/templates/page/index.html.eex
--- 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>
-

File Metadata

Mime Type
text/plain
Expires
Tue, Apr 7, 9:14 AM (15 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18841977
Default Alt Text
D327.1775553262.diff (4 KB)

Event Timeline