-
Notifications
You must be signed in to change notification settings - Fork 45
Selectors docs regarding use of NUMBER are incorrect (and a bad idea) #155
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
Comments
Thanks. This looks like two issues:
Let's use this issue to refine the wording in the Guide. I'll then file a bug to add the desired behavior to The motivation here is to be able to tell The spec should mention that the decimal part of the number is significant, even if it's all zeros. We shouldn't format the number however, as that might produce non-digits, too, and use different separators. The implementation might actually need to build a custom representation of the number just for this comparison. Does this sound like a reasonable thing to do? |
@stasm - In terms of fixing fluent.js, it seems workable, although I'm wondering where the data would come from for this. Does CLDR even distinguish this case? AFAICS it doesn't. Also it seems like the algorithm for determining a match is already quite complex (and not clearly specified anywhere I can find, other than in the JS implementation), this could be making it even more complex. |
Actually, thinking some more, I'm confused about the need for this feature or how it should work. In English, your use case would be covered by:
i.e. you use the plural form 'kilos' always, because For other languages I don't know how it would work. |
It does. You can read more about it in https://www.unicode.org/reports/tr35/tr35-numbers.html#Language_Plural_Rules In particular, a lot about operands and CLDR plural rules syntax will help you recognize how much effort CLDR puts into that. And ECMA402 (new Intl.PluralRules("en", {minimumFractionDigits: 1}).select(1))
"other"
(new Intl.PluralRules("en", {minimumFractionDigits: 0}).select(1))
"one" |
@zbraniecki - thanks so much for that, it looks like I was misunderstanding based on what I was reading from Python Babel's implementation. In fact on further investigation Babel does also seem to support this correctly if you use |
Don't forget that applying NUMBER() to a small integer value may also even result invalid digits. Consider an Arabic user for whom NUMBER(123) may produce That said, using the plural system already handles the 1 vs 1.0 case in English:
Because
Presumably, if the number is formatted with a single fractional digit, the |
Here:
https://projectfluent.org/fluent/guide/selectors.html
The text claims that the formatted version of
$score
will be used to do the matching. In reality this doesn't happen in the reference implementation - see:The
0.0
is parsed as a number literal, converted to aFluentNumber
, and then compared by value to theFluentNumber
instance that results from the firstNUMBER
call. I added a test to the suite to confirm this, and it makes no difference if you change0.0
to0
or0.00
, or if you increase/decrease the value ofminimumFractionDigits
etc - it is doing a numerical comparison, not taking into account the formatting options.Further, the behaviour described in the docs would be a bad idea, AFAICS:
Number formatting can be quite expensive, we want to avoid it for selector matching.
If the formatted number should appear in the variant key expression, this presumably means it needs to be changed by translators e.g. in the example,
0.0
when considered as a string matches the formattedNUMBER
expression for English, but it would have to be changed to0,0
for German etc. I'm guessing translators would have confusion over whether to change these numbers like this.If the formatted number should appear in the variant key expression, all kinds of confusion occurs in terms of parsing/interpreting the FTL. For English locales, the formatted number looks like the number literal for small numbers (
1
,2.3
etc.), but not for large numbers (e.g.1,000
which is not a valid number literal.). For other locales, sometimes the formatted number will again not be a valid number literal, sometimes it might look like a number literal but for a different number (e.g.1.000
is German for one thousand, but would be parsed as a valid FTL number literal for one).The text was updated successfully, but these errors were encountered: