Skip to content
New issue

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

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

Already on GitHub? # to your account

V5 plural RangeError: Incorrect locale information provided #2095

Closed
1 task done
francois-pasquier opened this issue Nov 27, 2024 · 3 comments · Fixed by lingui/swc-plugin#133
Closed
1 task done

Comments

@francois-pasquier
Copy link

francois-pasquier commented Nov 27, 2024

Describe the bug
lowercase plural use results in RangeError: Incorrect locale information provided

To Reproduce

  • git clone git@github.com:lingui/js-lingui.git
  • git checkout next
  • cd examples/nextjs-swc

Does not work

import { plural } from '@lingui/core/macro'

export default function Developers() {
  return (
    <div>
      {plural(4, {
        zero: 'Developers',
        one: 'Developer',
        other: 'Developers'
      })}
    </div>
  )
}

Does work

import { Plural } from '@lingui/react/macro'

export default function Developers() {
  return (
    <div>
      <Plural value={4} one={'Developer'} other={`Developers`} />
    </div>
  )
}

Expected behavior
No error

Additional context
Plural component works out of the box, lowercase plural does not

  • jsLingui version lingui --version 5.0.0-next.4
  • Macro support:
  • I'm using SWC with @lingui/swc-plugin
  • Nextjs@14.2.15
@timofei-iatsenko
Copy link
Collaborator

This is misusage, plural as you used will use a global version of i18n which is not setup in that example. You should use plural macro together with a local i18n instance.

import { plural } from '@lingui/core/macro'
import { useLingui } from '@lingui/react/macro'

export default function Developers() {
  const {t} = useLingui();
  return (
    <div>
      {t`Hello we have ${plural(4, {
        zero: '# Developers',
        one: '# Developer',
        other: '# Developers'
      })}`}
    </div>
  )
}

@francois-pasquier
Copy link
Author

Thank you, it works indeed.

There is something broken when using it with arrow functions though.

import { plural } from '@lingui/core/macro'
import { useLingui } from '@lingui/react/macro'

const Developers = () => {
  const { t } = useLingui()
  return (
    <div>
      {t`Hello we have ${plural(4, {
        zero: '# Developers',
        one: '# Developer',
        other: '# Developers'
      })}`}
    </div>
  )
}

export default Developers

This ends up with Error: Incorrect locale information provided

@timofei-iatsenko
Copy link
Collaborator

Confirming the bug, would be fixed by lingui/swc-plugin#133

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

Successfully merging a pull request may close this issue.

2 participants