diff --git a/frontend/uxbox/locales.cljs b/frontend/uxbox/locales.cljs new file mode 100644 index 0000000000..4c3d05bb0d --- /dev/null +++ b/frontend/uxbox/locales.cljs @@ -0,0 +1,40 @@ +(ns uxbox.locales + "A i18n foundation." + (:require [hodgepodge.core :refer [local-storage]] + [cuerdas.core :as str] + [uxbox.locales.en :as locales-en])) + +(defonce +locales+ + {:en locales-en/+locales+}) + +(defonce +locale+ + (get local-storage ::locale :en)) + +(deftype C [val] + IDeref + (-deref [o] val)) + +(defn c + [x] + (C. x)) + +(defn ^boolean c? + [r] + (instance? C r)) + +(defn tr + "Translate the string." + ([t] + (let [default (name t) + value (get-in +locales+ [+locale+ t] default)] + (if (vector? value) + (or (second value) default) + value))) + ([t & args] + (let [value (get-in +locales+ [+locale+ t] (name t)) + plural (first (filter c? args)) + args (mapv #(if (c? %) @% %) args) + value (if vector? + (if (= @plural 1) (first value) (second value)) + value)] + (apply str/format value args)))) diff --git a/frontend/uxbox/locales/en.cljs b/frontend/uxbox/locales/en.cljs new file mode 100644 index 0000000000..c9bfce831f --- /dev/null +++ b/frontend/uxbox/locales/en.cljs @@ -0,0 +1,12 @@ +(ns uxbox.locales.en) + +(defonce +locales+ + {"ds.projects" "PROJECTS" + "ds.elements" "ELEMENTS" + "ds.icons" "ICONS" + "ds.colors" "COLORS" + "ds.library-title" "Library: " + "ds.standard-title" "STANDARD" + "ds.your-libraries-title" "YOUR LIBRARIES" + "ds.num-elements" ["%s element" + "%s elements"]})