-
Notifications
You must be signed in to change notification settings - Fork 599
Message: fix selectOrdinal. #639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The plural fuction used for messages only supported cardinals, not ordinals. This meant that selectOrdinal used the cardinal rules, not the ordinal rules. If the type option passed to Globalize.pluralGenerator is "both", the returned function accepts a second parameter. If this parameter is true, the function will return the ordinal category instead of the cardinal category. This is how messageformat.js expects the plural function to work.
Related to #563 |
Regarding your question there:
Here are two example messages:
The problem is that
I've highlighted the 1 in the first message which indicates to the plural function that it should use ordinals. |
So is this going to be fixed? I was just writing tests after integrating Globalize based message handling and realized that selectordinal doesn't actually work. Should I have not picked Globalize to handle i18n messages? |
Thanks for bringing this up. It indeed could break existing apps. We could conditionally-enable it only if such CLDR data is loaded, which would prevent to break existing apps, but internal logic would be a little convoluted and error handling in case someone intends to use ordinal but forgot to load it wouldn't be as great. Today I gave this approach a try, but in the end wasn't happy with the outcome. I'm sorry this took so long.
Yeap, that's the way we should proceed. I apologize for closing (instead of merging) this PR after so long. Sorry for the frustration. |
@dantman in the meantime, an approach that could be used (not as a replacement, but as an alternative solution) is to use Globalize.loadMessages({
en: {
foo:
"This is the {ordinal, select, one{1st} two{2nd} few{3rd} other{{count}th} } category"
}
});
let ordinalGenerator = Globalize.pluralGenerator({ type: "ordinal" });
[1, 2, 3, 4, 10].map(count =>
Globalize.formatMessage("foo", { count, ordinal: ordinalGenerator(count) })
);
// > [
// "This is the 1st category",
// "This is the 2nd category",
// "This is the 3rd category",
// "This is the 4th category",
// "This is the 10th category"
// ] |
@rxaviers Not an option in my situation. I'm using this in a system where messages and variable values are input by a user. I cannot tweak a variable input to go through a generator. |
The plural fuction used for messages only supported cardinals,
not ordinals. This meant that selectOrdinal used the cardinal
rules, not the ordinal rules.
If the type option passed to Globalize.pluralGenerator is "both",
the returned function accepts a second parameter. If this
parameter is true, the function will return the ordinal category
instead of the cardinal category.
This is how messageformat.js expects the plural function to work.
This introduces a minor BC break, because supplemental/ordinals.json must be loaded (I've fixed all the examples), although the documentation does suggest you need both.