Skip to content
Snippets Groups Projects
Commit 44002f6e authored by Tom Robinson's avatar Tom Robinson
Browse files

Clean up locale setting

parent e1707a28
No related branches found
No related tags found
No related merge requests found
......@@ -14,9 +14,10 @@ LOCALES_QUOTED=$(echo "$LOCALES" | awk '{ printf "\"%s\" ", $0 }')
FRONTEND_LANG_DIR="resources/frontend_client/app/locales"
# backend
# NOTE: include "en" even though we don't have a .po file for it because it's the default?
cat << EOF > "resources/locales.clj"
{
:locales #{$LOCALES_QUOTED}
:locales #{"en" $LOCALES_QUOTED}
:packages ["metabase"]
:bundle "metabase.Messages"
}
......
import React from "react";
import Select from "metabase/components/Select.jsx";
import _ from "underscore";
const SettingSelect = ({ setting, updateSetting, disabled }) =>
<Select
className="full-width"
placeholder={setting.placeholder}
value={setting.value}
value={_.findWhere(setting.options, { value: setting.value }) || setting.value}
options={setting.options}
onChange={updateSetting}
optionNameFn={option => typeof option === "object" ? option.name : option }
......
......@@ -55,10 +55,10 @@ const SECTIONS = [
key: "site-locale",
display_name: "Language",
type: "select",
options: [
{ name: "Default", value: "" },
...MetabaseSettings.get("available_locales").map(([value, name]) => ({ name, value }))
],
options: MetabaseSettings.get("available_locales").map(([value, name]) => ({
name,
value: value === "en" ? null : value // HACK: "en" is the default thus will be null
})),
placeholder: "Select a language"
},
{
......
......@@ -39,11 +39,11 @@
;; HACK: replace this with setting event listener
(defn sync-locale []
(let [site-locale (setting/get :site-locale)
(let [new-locale (or (not-empty (setting/get :site-locale)) "en")
current-locale (.toLanguageTag (Locale/getDefault))]
(log/info (trs "Hello World!"))
(if (and site-locale (not= current-locale site-locale))
(Locale/setDefault (Locale/forLanguageTag site-locale)))))
(if (not= current-locale new-locale)
(Locale/setDefault (Locale/forLanguageTag new-locale)))))
;;; CONFIG
......
......@@ -37,7 +37,8 @@
(defsetting site-locale
"The default language for this Metabase instance. This only applies to emails, Pulses, etc. Users' browsers will specify the language used in the user interface."
:type :string)
:type :string
:default "en")
(defsetting admin-email
"The email address users should be referred to if they encounter a problem.")
......
......@@ -2,6 +2,7 @@
(:require [cheshire.core :as json]
[clojure.java.io :as io]
[clojure.string :as str]
[clojure.tools.logging :as log]
[compojure
[core :refer [context defroutes GET]]
[route :as route]]
......@@ -13,7 +14,7 @@
[routes :as api]]
[metabase.core.initialization-status :as init-status]
[metabase.util.embed :as embed]
[puppetlabs.i18n.core :refer [trs locale-negotiator user-locale]]
[puppetlabs.i18n.core :refer [trs locale-negotiator *locale*]]
[ring.util.response :as resp]
[stencil.core :as stencil]))
......@@ -33,10 +34,12 @@
(stencil/render-string (load-file-at-path path) variables))
(defn- load-localization []
(if (user-locale)
(log/info *locale*)
(if (and *locale* (not= (str *locale*) "en"))
(try
(load-file-at-path (str "frontend_client/app/locales/" (user-locale) ".json"))
(load-file-at-path (str "frontend_client/app/locales/" *locale* ".json"))
(catch Throwable e
(log/warn (str "Locale " *locale* " not found."))
"null"))
"null"))
......
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