7

I'm developing a mobile application using flutter / dart. The app needs to be localized using JSON files.

I need to handle the plural / gender in strings. Actually i'm using sprintf library, with some placeholder in the JSON code like:

{
  ...
   "vehiclelabelKmTraveledReadable": "In %s Km",
  ...
}

so I replaced the '%s' placeholder with a variable value.

The problem is how to handle plurals, like

{
"vehiclePeriod": "Every %s month(s?)"
}

But if %s is 1, it's wrong. Does anybody knows how to manage this kind of cases?

Biro
  • 199
  • 3
  • 16

1 Answers1

4

I managed this kind of case using intl package from flutter, but it uses .arb files instead of .json.

Here an example how to handle it with intl package

Intl.plural(howMany,
      zero: "$howMany An",
      one: "$howMany An",
      other: "$howMany Ans",
      name: 'dogYearsOld',
      locale: localeName,
      args: [howMany]);

Hope this can help you get started.

Slah Layouni
  • 650
  • 3
  • 9
  • 2
    I just saw arb files, and intl library, but i was wondering if in the json file i can use some kind of functions or similar... – Biro Jan 22 '20 at 11:42