Skip to content

Instantly share code, notes, and snippets.

@acobster
Created January 24, 2021 02:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acobster/c6994cb8efb4860a3c081b47d094b4ef to your computer and use it in GitHub Desktop.
Save acobster/c6994cb8efb4860a3c081b47d094b4ef to your computer and use it in GitHub Desktop.
Bread CMS i18n scratch
(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