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 pluralization rule is not working #882

Closed
5 tasks done
RollingTL opened this issue Jan 16, 2022 · 9 comments
Closed
5 tasks done

Custom pluralization rule is not working #882

RollingTL opened this issue Jan 16, 2022 · 9 comments

Comments

@RollingTL
Copy link

RollingTL commented Jan 16, 2022

Reporting a bug?

Hi,
I am trying to use custom pluralization function but it seems it is not working as expected:

The result is:

<p>1 машина</p>
<p>2 машины</p>
<p>4 машины</p>
<p>12 машины</p>
<p>21 машины</p>

Expected behavior

<p>1 машина</p>
<p>2 машины</p>
<p>4 машины</p>
<p>12 машин</p>
<p>21 машина</p>

12 and 21 result is wrong.

Reproduction

https://github.com/RollingTL/Testing-intlify-vue-i18n-next-custom-pluralization

System Info

Mac OS

Screenshot

No response

Additional context

No response

Validations

@RollingTL RollingTL added the Status: Review Needed Request for review comments label Jan 16, 2022
@RollingTL RollingTL changed the title Custom ploralization rule is not working Custom pluralization rule is not working Jan 16, 2022
@RollingTL
Copy link
Author

RollingTL commented Jan 16, 2022

I played with pluralization function and I think that it never called.
And one question what is the purpose of second and third argument? (choicesLength, orgRule)

@RollingTL
Copy link
Author

RollingTL commented Jan 16, 2022

After reading sources I have found the problem
Instead of pluralizationRules as in documentation the option should be pluralRules.

const i18n = createI18n({
  locale: 'ru',
  // the custom rules here ...
  **pluralRules**: {
    ru: customRule
  },
  messages: {
    ru: {
      car: '0 машин | {n} машина | {n} машины | {n} машин',
      banana: 'нет бананов | {n} банан | {n} банана | {n} бананов'
    }
  }
})

It is necessary to change documentation to fit source or source to fit documentation.

@kazupon
Copy link
Member

kazupon commented Jan 17, 2022

Thank you for your feedback.

About custom pluralization, vue-i18n@v9.x or later have a breaking change
You need to check docs here:
https://vue-i18n.intlify.dev/guide/migration/breaking.html#pluralization-api-return-value

In composition API, we don't mention custom pluralization.
We should improve the docs about custom pluralization.
https://vue-i18n.intlify.dev/guide/advanced/composition.html#pluralization

@kazupon kazupon removed the Status: Review Needed Request for review comments label Jan 17, 2022
@RollingTL
Copy link
Author

thank you for prompt reaction.

@FADL285
Copy link

FADL285 commented Sep 17, 2022

The problem is still found instead of 'pluralizationRules' as in documentation it should be 'pluralRules'

or change the code to be pluralizationRules

@mewforest
Copy link

OMG There is still an issue in documentation! 😮

The problem is still found instead of 'pluralizationRules' as in documentation it should be 'pluralRules'

@nulen
Copy link

nulen commented Mar 29, 2024

Yup, please fix it, chat gpt also suggests "pluralizationRules"

@BobbieGoede
Copy link
Member

As described in the documentation both pluralizationRules and pluralRules are the correct keys, it just depends on whether you're using the Composition API or the Options API.

  • pluralizationRules (Options/legacy API)
  • pluralRules (Composition API)

See https://vue-i18n.intlify.dev/guide/essentials/pluralization.html#custom-pluralization and compare highlighted lines in breaking changes with highlighted lines in breaking changes.

If you feel like this could be documented in a better way feel free to open a PR!

Yup, please fix it, chat gpt also suggests "pluralizationRules"

As for this, we have no control over what information chat GPT uses and it's your own responsibility to verify its output.

@Divensky
Copy link

Divensky commented Jun 5, 2024

@RollingTL earlier asked about the purpose of second and third argument (choicesLength, orgRule).

I found an explanation of the choicesLength as an overall amount of available choices. But I did not find an explanation of orgRule anywhere.

Could anyone help with this explanation? I wonder if it might help to customize rule sets for different words. Within a Slavic language, different words have different plural forms... choicesLength might help as workaround but I wonder if there is a direct way to set a rule for a specific group of words in that locale.

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

7 participants