Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks
etx121 opened this issue Oct 29, 2024 · 3 comments
Open
2 tasks

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

etx121 opened this issue Oct 29, 2024 · 3 comments

Comments

@etx121
Copy link

etx121 commented Oct 29, 2024

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
@timofei-iatsenko
Copy link
Collaborator

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

@etx121
Copy link
Author

etx121 commented Oct 29, 2024

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
Copy link
Author

etx121 commented Oct 29, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants