Description
Here:
https://projectfluent.org/fluent/guide/selectors.html
If the translation requires a number to be formatted in a particular non-default manner, the selector should use the same formatting options. The formatted number will then be used to choose the correct CLDR plural category which, for some languages, might be different than the category of the unformatted number:
your-score = { NUMBER($score, minimumFractionDigits: 1) -> [0.0] You scored zero points. What happened? *[other] You scored { NUMBER($score, minimumFractionDigits: 1) } points. }
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:
- https://github.com/projectfluent/fluent.js/blob/master/fluent/src/resolver.js#L222
- https://github.com/projectfluent/fluent.js/blob/master/fluent/src/types.js#L78 (FluentNumber.match)
- https://github.com/projectfluent/fluent.js/blob/master/fluent/src/types.js#L116 (FluentSymbol.match)
The 0.0
is parsed as a number literal, converted to a FluentNumber
, and then compared by value to the FluentNumber
instance that results from the first NUMBER
call. I added a test to the suite to confirm this, and it makes no difference if you change 0.0
to 0
or 0.00
, or if you increase/decrease the value of minimumFractionDigits
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).