js-lingui icon indicating copy to clipboard operation
js-lingui copied to clipboard

format props missing in <Plural> compared to the docs

Open etx121 opened this issue 1 year ago • 3 comments

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

  • jsLingui version 4.13.0
  • SWC version ("@lingui/swc-plugin) 4.0.9
  • Macro support:
  • [x ] I'm using SWC with @lingui/swc-plugin
  • [ ] I'm using Babel with babel-macro-plugin
  • [ ] I'm not using macro
  • Framework used: NextJs

etx121 avatar Oct 29 '24 12:10 etx121

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

timofei-iatsenko avatar Oct 29 '24 12:10 timofei-iatsenko

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 avatar Oct 29 '24 13:10 etx121

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

etx121 avatar Oct 29 '24 13:10 etx121