0

I originally misunderstood the usage of , as it seems it's only used for single-language applications.
Is there a way to pluralize message that use translations as well? For example, we have a simple line of code saying something like so:

{pluralize(formattedType, numberSelected, true)} Selected

Which would result in an output of "0 items Selected", "1 item Selected", "2 items Selected", etc.
Is there a way to incorporate similar logic with the formatjs library?

kastaplastislife
  • 293
  • 2
  • 16

1 Answers1

0

You can use MessageFormat

You can see the first example:

new IntlMessageFormat(
  `You have {numPhotos, plural,
      =0 {no photos.}
      =1 {one photo.}
      other {# photos.}
    }`,
  'en-US'
).format({numPhotos: 1})
NuLo
  • 1,298
  • 1
  • 11
  • 16
  • I think I was viewing this wrong all along. It's just a matter of giving the translators the right context in order to format this correctly once the string is extracted. – kastaplastislife Sep 16 '21 at 22:19
  • yes, you have to pass enough information so they can make the right decisions, there are lots of different scenarios in different languages – NuLo Sep 16 '21 at 22:31