unsplash / intlc

Compile ICU messages into code. Supports TypeScript and JSX. No runtime.
MIT License
56 stars 3 forks source link

`plural` and `selectordinal`: allow single case `other` #108

Closed OliverJAsh closed 2 years ago

OliverJAsh commented 2 years ago

Some languages might only have one plural form.

E.g. cardinal. We send:

{day, selectordinal, one {#st} two {#nd>} few {#rd} other {#th}}

They return:

{day, selectordinal, other {#}}

E.g. ordinal. We send:

{numberOfPhotos, plural, one {# photos} two other {# photos}}

They return:

{numberOfPhotos, plural, other {# abc}}

Currently intlc throws if the only case is other:

dayWithOrdinal:1:22:
  |
1 | {day, selectordinal, other {#}}
  |                      ^^^^
unexpected "othe"
expecting "few", "many", "one", "two", "zero", '=', or white space
samhh commented 2 years ago

The counter-argument in terms of correctness is that this could be {numberOfPhotos, number}.

I see three options:

  1. Leave it as-is, or ideally add a better parser error along the lines of "use the number type instead".
  2. Allow no non-wildcard cases, but produce a warning. This'd add the notion of linting in some capacity. This may be useful for developers producing master messages whilst not blocking translators using suboptimal syntax.
  3. Plainly allow no non-wildcard cases.

This also touches upon the broader question of whether and how we should favour correctness or acceptance (for want of a better word - think HTML in browsers). Vaguely related: #9, #27

samhh commented 2 years ago

One possible approach:

The first point gives translators maximum flexibility. The latter two allow us to maintain correctness in our master translations.

samhh commented 2 years ago

What should we do if there are two other wildcard cases? I think that should still error as the translator's intent is unclear?

OliverJAsh commented 2 years ago

Yeah agreed!

samhh commented 2 years ago

144 covered select. plural and selectordinal remain.