lingui / js-lingui

🌍 📖 A readable, automated, and optimized (3 kb) internationalization for JavaScript
https://lingui.dev
MIT License
4.64k stars 383 forks source link

format props missing in <Plural> compared to the docs #2072

Open etx121 opened 4 weeks ago

etx121 commented 4 weeks ago

Describe the bug I want to use Plural JSX element imported from: import { Plural } from "@lingui/macro"; In the documentation from the website https://lingui.dev/ref/macro#plural-1, it is reported that format is available. However, PluralChoiceProps doesn't contain it:

type PluralChoiceProps = {
  value: string | number
  /** Offset of value when calculating plural forms */
  offset?: number
  zero?: ReactNode
  one?: ReactNode
  two?: ReactNode
  few?: ReactNode
  many?: ReactNode

  /** Catch-all option */
  other: ReactNode
  /** Exact match form, corresponds to =N rule */
  [digit: `_${number}`]: ReactNode
} & CommonProps

Expected behavior format to be available in the <Plural> props

timofei-iatsenko commented 4 weeks ago

I'm not sure if this is implemented at all. Did you try to pass it ignoring the error?

etx121 commented 4 weeks ago

I just tried, but nothing is working. I tried Claude.ai's suggestion, but I have no idea how the format props work.

My use case is that in the plural, I would like to format the number to look like a local number:

<Plural
  value={value} // Pass the number directly
  _0="None"
  one={
    <Trans>
      <strong>{i18n.number(value)}</strong> day
    </Trans>
  }
  other={
    <Trans>
      <strong>{i18n.number(value)}</strong> day
    </Trans>
  }
/>

But the lingui extract will transform it into:

msgstr "{value, plural, =0 {None} one {<0>{0}</0> day} other {<1>{1}</1> days}}"

instead of

msgstr "{value, plural, =0 {None} one {<0>{value}</0> day} other {<1>{value}</1> days}}"

so it is easier for the translator to understand. Do you think it can be implemented?

etx121 commented 4 weeks ago

I corrected the link in the doc, in my first message: https://lingui.dev/ref/macro#plural-1