This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-18
Channels
- # adventofcode (326)
- # aws (1)
- # beginners (67)
- # cider (52)
- # cljs-dev (5)
- # cljsrn (5)
- # clojure (104)
- # clojure-art (2)
- # clojure-austin (34)
- # clojure-france (12)
- # clojure-greece (38)
- # clojure-india (2)
- # clojure-italy (6)
- # clojure-spec (11)
- # clojure-uk (32)
- # clojurescript (51)
- # core-async (5)
- # cursive (11)
- # data-science (5)
- # datascript (3)
- # datomic (3)
- # defnpodcast (7)
- # fulcro (26)
- # graphql (10)
- # hoplon (1)
- # instaparse (2)
- # jobs (1)
- # klipse (3)
- # lumo (13)
- # off-topic (50)
- # om (2)
- # onyx (19)
- # parinfer (1)
- # pedestal (4)
- # re-frame (18)
- # ring-swagger (1)
- # spacemacs (1)
- # specter (42)
- # sql (9)
- # uncomplicate (18)
- # unrepl (13)
Hi all, is it safe to use the internationalization macros e.g. tr
on app state strings?
Hello @levitanong. According to the doc the string must be literal: https://github.com/fulcrologic/fulcro/blob/develop/src/main/fulcro/i18n.cljc#L123-L126
@piotrek yeah, but i was thinking of putting in initial state (prim/get-initial-state Component {:some-string (tr "asdf")})
The tr
macro checks its argument during the compilation time so (prim/get-initial-state Component {:some-string (tr "asdf")})
will be actually a list, not a string and it will fail. I don’t know the internals so I am not sure if it could handle dynamic values or not.
ooooh, okay thanks @piotrek!
Possibly useful: the source code is available for Sulolive, an online marketplace built as a full-stack Clojure app using Datomic and Om.Next: https://github.com/eponai/sulolive
@levitanong So, i18n works as follows: There is tr
and tr-unsafe
. The string extraction step can only extract literal strings, so tr
gives an error if you try to use a variable with it (tr v)
; however, it is common to need to do such a thing, in which case you use tr-unsafe
instead (which cannot participate in i18n extraction).
Then, you can easily scan the code for tr-unsafe
at translation time, and add the necessary translations for the things that might appear in the variable
So, a dropdown that can have “yes”, “no”, “maybe” would format with tr-unsafe
, and then hand-add those three strings to the pot file, the po files, and then generate the translation code…that will cause them to work at runtime.
There should probably be a few additions/improvements to this, but no one has really asked for them yet. For example, having it just be a warning of some kind would be sufficient, or having the warning be at extraction time. Open to these improvements, so feel free to comment on your experience.
I’d also like to build an interface that lets you translate in the app itself. Like fulcro-inspect…where you could put in the translations in the UI. It would be relatively easy to implement…in fact, fulcro-inspect might be a great template for writing such a thing.
The would eliminate the need for the extraction and generation steps to be external…it could just generate the code live while you edit via the UI of the app itself.
Also, remember that translations are active functions, so translating something into app state is probably not what you want.
@tony.kay thanks for the detailed response! I’ve only just started with fulcro (definitely a breath of fresh air over om.next! Thanks for this.) so I can’t give much feedback at the moment. This is useful information, and I see I’ve been approaching a certain part of my app the wrong way. Thanks for pointing me in the right direction!
Look at the docstring @decoursin
https://github.com/fulcrologic/fulcro/blob/2.0.0-RC2/src/main/fulcro/client/primitives.cljc#L3212