formatjs / intl-messageformat

[MIGRATED] Format a string with placeholders, including plural and select support to create localized messages.
http://formatjs.io/
Other
530 stars 77 forks source link

Requiring `other` cases in plural, select, and selectordinal arguments #129

Closed eemeli closed 5 years ago

eemeli commented 8 years ago

It would appear that intl-messageformat is not requiring an other case in arguments. The original Java implementation does have this requirement, from where messageformat.js has adopted it as well:

You always have to define a phrase for the default keyword other; this phrase is returned when the keyword provided to the format method matches no other keyword. If a pattern does not provide a phrase for other, the method it's provided to returns the error U_DEFAULT_KEYWORD_MISSING.

As a consequence, a source string like Test {x, select, true{this}} will compile with intl-messageformat, but not with messageformat.js. This is a problem for migrating from one implementation to the other, as we've now discovered with SlexAxton/messageformat.js#141.

It would be good if we could resolve this discrepancy. How would you feel about introducing a compile-time check for other to intl-messageformat, to bring it in line with other ICU MessageFormat implementations?

ericf commented 8 years ago

Yeah seems good to me. Not sure when I'll have a chance to get to this though.

ggarek commented 8 years ago

I am also interested in this feature, and i would like to help on it. @ericf I may not know how you wish to implement it so i opened a PR with first steps as i see it.

One thing that would be very useful, but may need a bit of refactoring, is the ability to incorporate the original message within the compiler error. I did not find a simple way to do it, because a compiler never gets the original message.

I will be glad to update the PR if you share your vision on how it should be implemented.

longlho commented 5 years ago

See #186 for more context