Skip to content

extract-intl / defineMessages #7

Open

Description

@ArsSirek

Hi, thanks for sharing this package!

Sorry, if I missed something, but is there, or will there be a way to extract a messages and build a translation.json files?

I mean something like what react-boilerplate do with command extract-intl ? Or what is recommendations to generate the files?

I may be wrong, but I checked the code and, it seems to me, that adding
defineMessages may make this project compatible with babel-plugin-react-intl, isn't it ?
The though is based on this lines . Can we replace the name and get the results?

Best regards,

Activity

  1. ArsSirek commented on Jun 22, 2017

    @ArsSirek
    Author

    Hi here again!
    I was able to successfully switch to your project from react-intl! thanks! (with few things to be aware, though)

    It turns out that we actually can use babel-plugin-react-intl and logic with defineMessages with this react-intl-universal as well, the only problem I faced was with the fact that there is no defineMessages function here, and my attempted to add one failed, because if we import defineMessages from this repo that will broke the extract-intl with error about "window" being undefined. If I get it right, this project doesn't meant to work on server side yet?

    I ended up adding a project just to separate defineMessages, hope we will come with something better )

  2. cwtuan commented on Jun 22, 2017

    @cwtuan
    Collaborator

    Thanks for the suggestion.

    Actually, I'm also researching if there's better way to extract messages. I hadn't use extract-intl before. But I will try your example first these days then fulfill this feature.

    By the way, could you please tell me what's "few things to be aware" you mentioned?

  3. ArsSirek commented on Jun 22, 2017

    @ArsSirek
    Author

    @cwtuan, thanks,
    sure, I thought, to list them, but then thought, that I could have missed something... (correct me, please, if I am wrong somewhere with this)

    1. in react-intl-universal the work with date and datetime just differ, there is no FormattedTime, FormattedDate. And no stright way to use react-intl-universal to render formatted time without adding a line in translation.json . In my case, I am using momentjs as well, so I replaced my usage of FormattedTime as FormattedDate with momentJsObjectWithTime.format('LT') and .format('L') respectfully.
    2. react-intl allows to pass react objects as values for messages with variables, I may missed something, but with straight replacing FormattedHTMLMessage with .fromatHTMLMessage a got [Object] [object] . I still didn't resolve this, and wanted to open an issue to ask, but I think for my case I will be able to workaround somehow even if we will not be able to support the feature.
    3. the part with defineMessages mentioned in this issue
    4. the synchronization of the components with changed locale, if I get it right, one of your recommendations to this is reloading the page, as you do in demo, but that may be not what people expect with react, I was able to solve this easily, because I use mobx-react with MST I just added a prop locale={store.locale} to all components with calls to intl and it worked fine.

    As for my example of extract-intl it is not complete in my repository, you can look for it the original react-boilerplate extract-intl I only changed paths to fit my structure, removed unnecessary parts that change other files expect actual translation json(s) and added a right name for the repository from which difineMessages is imported

  4. cwtuan commented on Jun 25, 2017

    @cwtuan
    Collaborator

    @ArsSirek Thanks for your comment. It really help me a lot to improve this project. I will take your suggestions into consideration in next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions