alibaba / react-intl-universal

Internationalize React apps. Not only for Component but also for Vanilla JS.
1.33k stars 154 forks source link

should variables apply when defaultMessage is used? #8

Open ArsSirek opened 7 years ago

ArsSirek commented 7 years ago

Hi, Not sure if it is a bug, but with my usage of extract-intl, I had a case, when the locale message was actually an empty string, so we passed this null check variables had no effect, and the defaultMessage is shown in the end with {variable} as in "locale.json".

I don't know what is a right thing to do, but it seems to me that the desired result would be to have variables inserted into defaultMessage as well.

Thanks!

cwtuan commented 7 years ago

Could you show the detail of this case? How do you use defaultMessage method?

ArsSirek commented 7 years ago

Hi, I wrote an example showing my usage, wasn't sure how to provide it, so I forked and added it here in examples folder #10

And there is a branch on that fork, that shows a problem I mentioned in this issue to reproduce you can,

Panoplos commented 6 years ago

Actually, variables are ignored in the case of using intl.get('something', {foo}).d('something {foo} bar'), so this seems like a bug, as this call results in 'something {foo} bar'. Kind of meaningless to have defaults if this is the case.

cwtuan commented 6 years ago

@Panoplos It should be intl.get('something', {foo}).d(`something ${foo} bar`)

Panoplos commented 6 years ago

The documentation doesn't mention this.

screen shot 2018-04-26 at 12 11 41
Panoplos commented 6 years ago

Or rather, it does in the API section, but why is the default variable tag spec different from the locale data?

We have a script that automatically scrapes out defaults to build the base locale, having these be different requires us to remove the $.

cwtuan commented 6 years ago

@Panoplos The defaultMesssage is now ES6 Template literals format. And the locale file is ICU format.

I will make this intl.get('something', {foo}).d('something {foo} bar') work, too, in next release. Thanks for the suggestion.

liuyiliuyi commented 2 years ago

@cwtuan Hi, is there any progress.

cwtuan commented 2 years ago

@liuyiliuyi After reconsideration, I'd like to remain the current behavior for this API, because this proposal may make break changes.

And you could use react-intl-universal-extract to extract the text in source code to locale files. It will remove the $ automatically.