Skip to content

Instantly share code, notes, and snippets.

@whamtet
Created September 23, 2016 05:12
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 whamtet/9085204fb6c6489630d7b7b5da58fc9a to your computer and use it in GitHub Desktop.
Save whamtet/9085204fb6c6489630d7b7b5da58fc9a to your computer and use it in GitHub Desktop.
private static load_string = clojure.java.api.Clojure.var('clojure.core', 'load-string')
private static localization = load_string.invoke('''
(require '[clojure.java.io :as io])
(defn cljs-resource [path] ;does this work in production?
(io/resource (str "META-INF/assets/taipan_reagent/src/" path)))
(defn needed-messages [path]
(distinct (map second (re-seq #"\\(messages \\"(\\w+?)\\"\\)" (slurp (cljs-resource path))))))
(fn [request application-context path]
(let [locale (org.springframework.web.servlet.support.RequestContextUtils/getLocale request)]
(pr-str
(into {} (map #(vector % (.getMessage application-context (str "my.localized." %) nil locale)) (needed-messages path))))))
''')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment