Created
January 24, 2021 02:15
-
-
Save acobster/c6994cb8efb4860a3c081b47d094b4ef to your computer and use it in GitHub Desktop.
Bread CMS i18n scratch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn translate-string [s] s) | |
;; TODO ideas for i18n | |
;; Dispatch on content field vs. hard-coded transation keys in markup... | |
(def html [:html {:lang "en"} | |
[:head | |
[:title :text/hello]] | |
[:body | |
[:main | |
[:h1 :text/hello] | |
[:h2 :text/invalid] | |
[:article (tpl/dangerous (translate-string "Some rich text content..."))]]]]) | |
;; Here we delegate to tempura or similar | |
;; https://github.com/ptaoussanis/tempura | |
(defn tr [x] | |
(let [dict {:missing "MISSING" | |
:hello "Hello"}] | |
(get dict x (:missing dict)))) | |
(defn i18n [x] | |
;; TODO | |
(if (and (keyword? x) (= "text" (namespace x))) | |
(tr (keyword (name x))) | |
x)) | |
(clojure.walk/postwalk i18n html) | |
(defn profiler-for-hooks [hooks f] | |
(fn [call] | |
(when (contains? hooks (:hook call)) (f call)))) | |
(defn prn-keys [ks m] | |
(prn (select-keys m ks))) | |
(binding [bread/*hook-profiler* (profiler-for-hooks #{:hook/render} (partial prn-keys [:hook :args]))] | |
(handler {:url "one"}) | |
(slurp "dist/one.html")) | |
(:body (handler {:url "two"})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment