question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Impossible to add pluralizationRules via the vueI18n options

See original GitHub issue

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)

<div align="right">This bug report is available on Nuxt community (#c209)</div>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:9
  • Comments:7

github_iconTop GitHub Comments

9reactions
pampi848commented, Nov 29, 2021

@lukaVarga try pluralRules instead of pluralizationRules

2reactions
rchlcommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pluralization | Vue I18n
In order to implement these rules you can pass an optional pluralizationRules object into VueI18n constructor options.
Read more >
Impossible to add pluralizationRules via the vueI18n options
In nuxt.config.js , within the options for the nuxt-i18n module, add a vuei18n option; Add pluralizationRules: {'en': function(choice, ...
Read more >
Pluralization | Vue I18n
These plural messages are selected by the logic of the choice rule for each language in the translaton API according to the numeric...
Read more >
Vue i18n: Building a multi-language app with locale switcher
Installing and setting up Vue I18n. Adding support for multiple languages. Storing and using translations. Implementing pluralization.
Read more >
The Ultimate Vue Localization Guide | Phrase
Dive into Vue localization and learn how to plug the Vue I18n library into your app, so you can make it accessible to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found