Fork me on GitHub

Hi all, is it safe to use the internationalization macros e.g. tr on app state strings?


@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:


@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.


if the locale changes, you don’t want to have to change all of your app state.


@tony.kay thanks for the detailed response! I’ve only just started with fulcro (definitely a breath of fresh air over! 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!


Lein template updated to allow you to elide the demo code.


How do I do react lifecycle functions with defsc? Like componentDidUpdate


Look at the docstring @decoursin


or the dev guide


Thank you very much!


Do you plan on maintaining support for defui or eventually only defsc?


Stuff is pretty heavily documented. I’m updating the getting started guide as we speak.


The Developer’s Guide and doc strings should be pretty up-to-date.