phrase / phrase-cli

CLI for the Phrase API
https://developers.phrase.com
MIT License
42 stars 6 forks source link

Pluralization with ARB files #90

Closed landyrev closed 2 years ago

landyrev commented 2 years ago

Flutter i18n has its own way to encode plurals in ARB files (see Flutter Internationalization User Guide). For example:

{
  "nWombats": "{count,plural, =0{no wombats} other{{count} wombats}}",
  "@nWombats": {
    "description": "A plural message",
    "placeholders": {
      "count": {}
    }
  }
}

i18n codegenerator converts this object into handy method String nWombats(num count)

But when I use Phrase I'm facing two problems:

  1. Plurals are being pulled from Phrase to ARB files as separate i18n keys (like nWombatsZero, nWombatsOne, nWombatsOther), so I have to implement pluralization logic on my own
  2. Flutter plurals are not being parsed during the push operation, so I have to work with raw values in the Phrase Editor, which is quite unusable, especially if you work with external translators (see example screenshot)
theSoenke commented 2 years ago

Hi @landyrev, I suggest enabling ICU in the settings of your project. You can find this at: Project Settings -> Advanced -> Enable ICU Message format. After that ICU translations will be properly highlighted and should make editing for translators quite a bit easier.

For example, your translation would look like this:

icu-example

In addition, you would have to disable pluralization for all keys that are using ICU. After this you'll also get proper ICU pluralization in your arb file when pulling it.

landyrev commented 2 years ago

Thank you, @theSoenke, it helped 🙌

landyrev commented 2 years ago

it might be useful to enable this option by default for flutter projects though