Skip to content
Snippets Groups Projects
Unverified Commit c57328da authored by Cam Saul's avatar Cam Saul
Browse files

Fix loading i18n files :abcd:

parent e309f287
No related branches found
No related tags found
No related merge requests found
......@@ -14,7 +14,8 @@
[i18n :refer [trs]]]
[puppetlabs.i18n.core :refer [*locale*]]
[ring.util.response :as resp]
[stencil.core :as stencil]))
[stencil.core :as stencil])
(:import java.io.FileNotFoundException))
(defn- base-href []
(let [path (some-> (public-settings/site-url) io/as-url .getPath)]
......@@ -40,9 +41,10 @@
(or
(when (and locale (not= locale "en"))
(try
(slurp (str "frontend_client/app/locales/" locale ".json"))
(slurp (or (io/resource (str "frontend_client/app/locales/" locale ".json"))
(throw (FileNotFoundException. (str (trs "Locale ''{0}'' not found." locale))))))
(catch Throwable e
(log/warn (trs "Locale ''{0}'' not found." locale)))))
(log/warn (.getMessage e)))))
(fallback-localization locale)))
(def ^:private ^{:arglists '([])} load-localization
......
(ns metabase.routes.index-test
(:require [cheshire.core :as json]
[expectations :refer [expect]]
[metabase.routes.index :as index]
[puppetlabs.i18n.core :refer [*locale*]]))
;; make sure `load-localization` is correctly loading i18n files (#9938)
(expect
{"charset" "utf-8"
"headers" {"mime-version" "1.0"
"content-type" "text/plain; charset=UTF-8"
"content-transfer-encoding" "8bit"
"x-generator" "POEditor.com"
"project-id-version" "Metabase"
"language" "es"
"plural-forms" "nplurals=2; plural=(n != 1);"}
"translations" {"" {"Your database has been added!" {"msgstr" ["¡Tu base de datos ha sido añadida!"]}}}}
(some->
(binding [*locale* "es"]
(#'index/load-localization))
json/parse-string))
;; if locale does not exist it should log a message and return the 'fallback' localalization (english)
(expect
{"headers" {"language" "xx", "plural-forms" "nplurals=2; plural=(n != 1);"}
"translations" {"" {"Metabase" {"msgid" "Metabase", "msgstr" ["Metabase"]}}}}
(some->
(binding [*locale* "xx"]
(#'index/load-localization))
json/parse-string))
;; english should return the fallback localization (english)
(expect
{"headers" {"language" "en", "plural-forms" "nplurals=2; plural=(n != 1);"}
"translations" {"" {"Metabase" {"msgid" "Metabase", "msgstr" ["Metabase"]}}}}
(some->
(binding [*locale* "en"]
(#'index/load-localization))
json/parse-string))
{
"charset": "utf-8",
"headers": {
"mime-version": "1.0",
"content-type": "text/plain; charset=UTF-8",
"content-transfer-encoding": "8bit",
"x-generator": "POEditor.com",
"project-id-version": "Metabase",
"language": "es",
"plural-forms": "nplurals=2; plural=(n != 1);"
},
"translations": {
"": {
"Your database has been added!": {
"msgstr": [
"¡Tu base de datos ha sido añadida!"
]
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment