taoensso / tempura

Simple text localization library for Clojure/Script
https://www.taoensso.com/tempura
Eclipse Public License 1.0
260 stars 16 forks source link

Warn users CLJS loading from resource files isn't supported #5

Closed pld closed 7 years ago

pld commented 7 years ago

It isn't obvious from the README that CLJS loading from resource files isn't supported, https://github.com/ptaoussanis/tempura/blob/master/src/taoensso/tempura/impl.cljc#L347

We got around this in tower, and now in tempura, by loading the resources into a dict at compile-time for the CLJS,

(ns i18n
  #?(:cljs
     (:require-macros [i18n :refer [compile-dictionary]]))
  (:require [taoensso.tempura.impl :as impl]))

(def dictionary {:en {:__load-resource "translations/en.clj"}})

#?(:clj
   (defmacro compile-dictionary
     "Macro for a compile-time dictionary from resources files to use in CLJS."
     []
     (impl/compile-dictionary false dictionary)))

(def opts
  "Reload files from disk in CLJ, load precompiled files in CLJS."
  {:dict #?(:clj dictionary
            :cljs (compile-dictionary))})

using something similar to the snippet above.

It'd be great to have external resources work in CLJS without the above. @ptaoussanis is there a principled reason this wasn't included? Would you be interested in a PR for this? I don't have the time right now, but I'd like to see this in a release and would try to make time for it when I could.

ptaoussanis commented 7 years ago

Hi Peter, appreciate you pinging about this. Would be happy to see a PR if you have a specific approach in mind that you think would work well - thanks! :-)

Cheers

ptaoussanis commented 7 years ago

Will offer some guidance on this, and an alternative on the next Tempura release - cheers! :-)