gpbl/isomorphic500

Troubles using <FormattedMessage... >

maiopirata opened this issue · 3 comments

I'm having some troubles using <FormattedMessage... >

It works most of the times, but sometimes when I'm trying to use it to print a string inside an html tag it returns [Object object].
For exemple if I try to print the location of an image as:
<img src=<FormattedMessage message="img.location"> />

I know that the img.location doesn't need to be internationalized but eventually a tooltip does!

gpbl commented

Hi @maiopirata you can't use the components to produce a string, they are meant to output react HTML elements (hence, objects). To produce a string, you can use this.formatMessage included in the ReactIntlMixin (see this issue, which applies to input placeholders).

If you are not using the mixins, or you are in some part of the code out of React components, then you need to implement your own formatMessage, e.g. using the same module used by ReactIntl, e.g. intl-messageformat. I adopted this way in the store for creating the document's <head>:
https://github.com/gpbl/isomorphic500/blob/master/src/stores/HtmlHeadStore.js#L64-L65

I agree this a weak part of ReactIntl. Maybe @ericf can tell us more about the plans for the next releases :-)

Hi @gpbl, thanks for your reply...

I'll try to fix it today or tomorrow as in your suggestion!

gpbl commented

👍 let us know how it goes...