mirror of
https://github.com/penpot/penpot.git
synced 2026-08-01 10:56:20 +00:00
Add initial i18n foundation.
This commit is contained in:
parent
80ab99e8cf
commit
4b7d18128c
40
frontend/uxbox/locales.cljs
Normal file
40
frontend/uxbox/locales.cljs
Normal file
@ -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))))
|
||||||
12
frontend/uxbox/locales/en.cljs
Normal file
12
frontend/uxbox/locales/en.cljs
Normal file
@ -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"]})
|
||||||
Loading…
x
Reference in New Issue
Block a user