dart-lang / i18n

A general mono-repo for Dart i18n and l10n packages.
BSD 3-Clause "New" or "Revised" License
64 stars 40 forks source link

Support for explicit 0 and 1 rules for number formatting #21

Open shihaohong opened 3 years ago

shihaohong commented 3 years ago

Original Flutter issue: https://github.com/flutter/flutter/issues/84291 Taken directly from https://unicode-org.github.io/cldr/ldml/tr35-numbers.html#Explicit_0_1_rules:

Some types of CLDR data (such as unitPatterns and currency displayNames) allow specification 
of plural rules for explicit cases “0” and “1”, in addition to the language-specific plural cases specified 
above: “zero”, “one”, “two” ... “other”:

- The explicit “0” and “1” cases are not defined by language-specific rules, and are available in any 
language for the CLDR data items that accept them.
- The explicit “0” and “1” cases apply to the exact numeric values 0 and 1 respectively. These cases
are typically used for plurals of items that do not have fractional value, like books or files.
- The explicit “0” and “1” cases have precedence over the “zero” and “one” cases. For example, if 
for a particular element CLDR data includes values for both the “1” and “one” cases, then the “1” 
value is used for numeric values of exactly 1, while the “one” value is used for any other formatted 
numeric values matching the “one” plural rule for the language.
mosuem commented 2 years ago

I am not sure I understand this correctly, but this is quoting the LDML rules for CLDR data - intl supports the ICU MessageFormat, which explicitly states

Note: In a plural argument like in the example above, if the English message has both =0 and =1 (up to =offset+1) then it does not need a “one” variant because that would never be selected. It does always need an “other” variant.

Also, while =1 and one are semantically different, there is are no differences in the result. The only benefit I see is the ease of use for translators, who may be used to one, two etc. Am I missing something?

alan-knight commented 2 years ago

See https://github.com/dart-lang/i18n/issues/215 , although that's also talking about formatting of the plural parameter.

These can have different semantics. =1 means exactly one. 'one', means singular, which can be different, with Russian as a particularly tricky example. And they also mention formatting fractional values as plurals, though I don't think this package really supports that. The handling of this is confusing, since we have named parameters zero/one, but emit =0 and =1. On parsing, I think we treat them specially as well, though the details are fuzzy. But it's a long-standing pain point.

On Thu, Oct 20, 2022 at 4:33 AM Moritz @.***> wrote:

I am not sure I understand this correctly, but this is quoting the LDML rules for CLDR data - intl supports the ICU MessageFormat, which explicitly states https://unicode-org.github.io/icu/userguide/format_parse/messages/

Note: In a plural argument like in the example above, if the English message has both =0 and =1 (up to =offset+1) then it does not need a “one” variant because that would never be selected. It does always need an “other” variant.

Also, while =1 and one are semantically different, there is are no differences in the result. The only benefit I see is the ease of use for translators, who may be used to one, two etc. Am I missing something?

— Reply to this email directly, view it on GitHub https://github.com/dart-lang/i18n/issues/21, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2QU6FEIKRIJDA3BFK5UD3WED7UVANCNFSM47CRFXOA . You are receiving this because you are subscribed to this thread.Message ID: @.***>