Incorrect translations when implementing pluralization in ICU message format. I'm using react-intl (format.js)

206 views Asked by At

It seems like using pluralization in ICU message format is not dependable when combined with static text.

Take the following example:

Please see the {itemCount, plural,
  one {message}
  other {messages}
} in your inbox.

In Spanish, the word "the" changes depending on whether or not it's plural. The correct translations in Spanish should be:

one: "Por favor vea el mensaje en su bandeja de entrada"
other: "Por favor vea los mensajes en su bandeja de entrada"

The way to solve this would be to include "the" in the conditional.

Developers are obviously not going to be fluent in every language their app supports. If you don't speak Spanish, you wouldn't know to include "the" in the conditional.

It seems irresponsible to allow this type of syntax. Format.js even promotes using pluralization like this in their examples: https://formatjs.io/docs/core-concepts/icu-syntax/#plural-format

It seems to me that an error should be thrown when attempting to combine static text with dynamic plural text. The entire sentence should be required in the conditional.

My question is: Am I missing something? Should I prohibit my developers from entering values like this?

I can't be the first person that noticed this. Is there a way to enforce this through a setting in Format.js?

1

There are 1 answers

3
Mark On

Looking at the documentation it looks as though your confusing the {selectordinal} with the message.

By way of an example the Spanish format based on what you have provided would be:

Por favor vea {itemCount, plural,
  one {el mensaje}
  other {los mensajes}
} en su bandeja de entrada.

Even so that is a relatively simple example as you may also have additional words later in the sentence affected by ordinal number, gender, or both so you may have to have multiple arguments in the sentence.

Declension is quite the fun linguistic topic for developers to get their heads around.

Edit: To add to this, that would give you something like:

const messages = {
  en: {
    INBOX: 'Please see the {itemCount, plural, 
        one {message}
        other {messages}
     } in your inbox.',
  },
  es: {
    INBOX: 'Por favor vea {itemCount, plural,
         one {el mensaje}
         other {los mensajes}
     } en su bandeja de entrada.',
  },
}

So for the Spanish it is necessary to move the 'the' into the argument, but not for the English. It is really down to the syntax and the person creating localised messages to utilise that syntax for whatever gendered or ordinal conditions they need to be aware of.