-
-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dict-compile
macro doesn't evaluate symbols
#54
Comments
Hey there, thanks for the suggestion! Could you try Cheers :-) |
Hey thanks for the super quick response. Eval! Of course. All those hours watching SICP lectures on youtube were wasted on me apparently... No success, but for other reasons:
Also I see the macro's changed from I've only ever had headaches using the leiningen checkouts feature otherwise I'd give that a go. Sorry I can't be more useful. |
No problem :-)
Not at all - Clojure macros don't generally use This is a bit of an unusual case since we're using a macro to dump the entire compiled dict into the ClojureScript source during ClojureScript compile time. I.e. we don't need the dictionary compilation to actually run under ClojureScript - if that makes sense.
It's possible I didn't upload it correctly - just tried again and it does seem to be up now: https://clojars.org/com.taoensso/tower/versions/3.1.0-SNAPSHOT
Ahh, yeah - you can add
Sorry, yeah - there's a number of changes (improvements) pending in the dev branch. It's stable (I'm using it now), but I haven't documented the changes yet. This is the only breaking change iirc. Hope that helps, cheers! :-) |
Awesome reply, thanks man. Alright I've got it, but still no dice. (some) dependencies: [org.clojure/clojure "1.6.0"]
[org.clojure/core.async "0.1.346.0-17112a-alpha"]
[org.clojure/clojurescript "0.0-2371"]
[com.taoensso/encore "1.15.1"]
[com.taoensso/sente "1.2.0"]
[com.taoensso/tower "3.1.0-SNAPSHOT"] i18n.cljx: (ns myns.i18n
#+cljs (:require-macros [taoensso.tower :as tower-macros])
(:require [taoensso.tower :as tower])
)
(def dict
{:en
{:test-msgs
{:one "One" :two "Two"}
}
}
)
#+clj
(def tconfig
{:dictionary "i18n-dict.clj"
:dev-mode? true ; FIXME: Make this dynamic
:fallback-locale :en
})
#+cljs
(def tconfig
{:compiled-dictionary (tower-macros/dict-compile* dict)
:fallback-locale :en})
(def t (tower/make-t tconfig)) error:
I'm not sure how to read this error - does that mean it doesn't know what For the record I've run this (overly safe) command multiple times to the same effect lein -U do clean, deps, compile The compile step in my setup is:
I hope this helps, if it's something I'm doing wrong I'd be grateful for the heads up. |
Hi there, Not really sure what the problem is - just ran a test and it does appear to be working on my end (no CLJS compilation errors). Would be happy to debug it with you, but I'm pretty swamped / on an urgent project atm. I'd start by checking that the As an alternative, I'd recommend just sticking your dictionary in a separate .clj file in your
This has a number of advantages and is the approach I take + tend to recommend. Any particular reason you're hesitant to go that route? |
I am getting the same exception as @lorddoig. I found that if I just structure the dict in the same fashion that dict-compile* produces then I can bypass using the macro all together. So (def dict
{:en
{:test-msgs
{:one "One" :two "Two"}
}
}
) becomes (def dict {
{:test-msgs/one {:en "One" }}
{:test-msgs/two {:en "Two" }}}) |
@smbecker Hi Shaun, I'd caution against that approach. Dictionary compilation involves more than just map restructuring (Markdown support & html escaping for example). In any case the compiled dictionary format is an implementation detail, so future versions may break compatibility with your pre-compiled dict. I'd suggest using a resource file if you can. Hope that helps, cheers! |
The basic problem that I am trying to solve is to write a macro that creates an accessor function for each of my localized strings. Since the clojurescript support doesn't support formatting, I have to manually format before passing the args to tower. Also, I am doing language detection on the browser to determine active locale. I don't want the rest of my code to have to worry about either of these details. That is why I was attempting to wrap all of that behind an a macro generated accessor. In order to generate the accessor's, I need access to the dict as well. I'm VERY much a clojure noob so I may be approaching it wrong in the first place (be patient with me). One thing that just occurred to me to try so I can accomplish what I want but still adhere to your caution is to still rely on dict-compile but to save the result of that to a variable the change my macro to be more of post processor rather than pre. Granted, I would still need to take some reliance on how dict-compile structures the output but I don't know any other way unless you have any suggestions. |
Still seeing this problem. Passing anything but anything but a map literal to
|
Hi Okal, what version of Tower are you running? I have |
Hm. I'm probably doing it wrong. I assumed it would be able to accept single language translation files of the following form: ;; en.clj
{:page-title "Home"} I'm attempting to call |
Added it properly, now it works. Thanks 😄 |
Happy to hear you've got it working. What inconsistency do you have in mind though? You should be able to inline a whole dictionary if you want, I just wouldn't normally recommend going that route unless you have a good reason. |
In CLJ, I can have arbitrary depth nesting in the lang maps, but that doesn't seem to be the case with CLJS. So, I can do To illustrate: {:main-navigation {:dropdown {:profile-link-text "Profile}}}
|
Cljs absolutely also supports arbitrary-depth nesting, but you must use valid keyword syntax: so Not sure if that's the specific issue you're running into, but it wouldn't surprise me if that keyword form were getting rejected in Cljs. |
I'm sure the title is explanation enough for seasoned macro-writers like yourselves, but for completeness:
fails because the library functions that actually compile the dictionary are given the symbol
dict
instead of the map.I'm new enough to Clojure that anything but simple macros make my head spin: I've tried and failed to fix this. I know it's easily worked around by just putting the dictionary in another file and passing in a string but I'm filing this anyway as I'm guessing this should be fixed/documented at some point.
The text was updated successfully, but these errors were encountered: