Fork me on GitHub
#fulcro
<
2017-12-18
>
levitanong09:12:35

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

levitanong10:12:35

@piotrek yeah, but i was thinking of putting in initial state (prim/get-initial-state Component {:some-string (tr "asdf")})

piotrek10:12:03

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.

levitanong10:12:22

ooooh, okay thanks @piotrek!

olivermooney14:12:25

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

tony.kay16:12:07

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

tony.kay16:12:36

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

tony.kay16:12:42

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.

tony.kay16:12:47

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.

tony.kay16:12:39

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.

tony.kay16:12:18

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.

tony.kay16:12:32

Also, remember that translations are active functions, so translating something into app state is probably not what you want.

tony.kay16:12:45

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

levitanong16:12:03

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

tony.kay19:12:44

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

decoursin19:12:50

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

tony.kay23:12:42

Look at the docstring @decoursin

tony.kay23:12:48

or the dev guide

decoursin06:12:52

Thank you very much!

decoursin06:12:00

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

tony.kay23:12:35

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

tony.kay23:12:13

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