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

Impossible to add pluralizationRules via the vueI18n options #237

Closed
lukaVarga opened this issue Mar 4, 2019 · 7 comments · Fixed by #605
Closed

Impossible to add pluralizationRules via the vueI18n options #237

lukaVarga opened this issue Mar 4, 2019 · 7 comments · Fixed by #605

Comments

@lukaVarga
Copy link

lukaVarga commented Mar 4, 2019

Version

v5.3.0

Reproduction link

Not really needed

Steps to reproduce

  1. In nuxt.config.js, within the options for the nuxt-i18n module, add a vuei18n option
  2. Add pluralizationRules: {'en': function(choice, choicesLength) { return 0 }} object
  3. run npm run dev

What is expected ?

The generated .nuxt/nuxt-i18n/plugin.main.js file should initialize new VueI18n with pluralizationRules: {'en': function(choice, choicesLength) { return 0 }} parameter

What is actually happening?

pluralizationRules is an empty object

Additional comments?

This happens because the vuei18n options get stringified using JSON.stringify here. The result of JSON.stringify({foo: function() {return 'bar'}}) is an empty object as the method serializes function as null value as you can see here

The option to initialize VueI18n with pluralization rules was added recently (see discussion)

This bug report is available on Nuxt community (#c209)
@ghost ghost added the cmty:bug-report label Mar 4, 2019
@AndrewBogdanovTSS
Copy link

Any updates regarding this issue?

@stale
Copy link

stale bot commented Jun 23, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jun 23, 2019
@stale stale bot closed this as completed Jun 30, 2019
@AndrewBogdanovTSS
Copy link

This issue is not fixed, please, reopen

@rchl
Copy link
Collaborator

rchl commented Jul 1, 2019

Passing functions through module options would require serialization of function and that is, while possible, generally discouraged by core team. Better option is to support external configuration file that would be required by the module. Then you can use functions without problems.

But I agree it should be re-opened.

@oppianmatt
Copy link

this is the same problem that causes custom formatter not to work, raised issue here #585

the json.stringify removes any functions/methods so you can't pass a custom formatter as an option

@rchl rchl reopened this Feb 7, 2020
@stale stale bot removed the wontfix label Feb 7, 2020
@rchl rchl closed this as completed in #605 Feb 24, 2020
rchl added a commit that referenced this issue Feb 24, 2020
Added support for specifying path to local file for options passed to
vue-i18n (the `vueI18n` key of `nuxt-i18n` configuration). This allows
for configuration some options that have function type which previously
would fail due to stringifying and lack of possibility to import stuff.

Resolves #585, resolves #237
@pampi848
Copy link

pampi848 commented Nov 29, 2021

@lukaVarga try pluralRules instead of pluralizationRules

@parabellumKoval
Copy link

Here is the answer #605
This issue is solved by adding an external configuration file.

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

Successfully merging a pull request may close this issue.

6 participants