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

Custom pluralRules not working #143

Open
josemigallas opened this issue Mar 25, 2020 · 1 comment
Open

Custom pluralRules not working #143

josemigallas opened this issue Mar 25, 2020 · 1 comment

Comments

@josemigallas
Copy link

Hi, is the documentation about pluralRules still accurate? I'm having some trouble defining my own.. it doesn't seem to work. Here's my definition, I copy pasted if from the Readme and modify it:

const polyglot = new Polyglot({
  locale: 'foo',
  phrases: {
    messages: 'You have no new messages.||||You have %{smart_count} new message.||||You have %{smart_count} new messages.',
  },
  pluralRules: {
    pluralTypes: {
      noneLike: function (n) {
        if (n === 0) return 0;
        if (n === 1) return 1;
        return 2;
      },
    },
    pluralTypeToLanguages: {
      noneLike: ['foo']
    }
  }
});

It should print:

You have no new messages.
You have 1 new message.
You have 30 new messages.

But instead it's:

You have 0 new message.
You have no new messages.
You have 30 new message.

I wrote a CodePen: https://codepen.io/josemigallas/pen/poJxYNX

@ljharb
Copy link
Collaborator

ljharb commented Mar 25, 2020

You're using v2.2.2 in that codepen; try with v2.4.0? (which isn't on cdnjs)

See also a5684b5; the build files being used on cdnjs haven't been updated since v0.4.3, so I don't think it would have this feature.

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