[Feature request] - Override of the getChoiceIndex function should be available via options object on initialization
See original GitHub issueI use vue-i18n
via another lib nuxt-i18n
so I doesn’t have direct access to the library to override getChoiceIndex
method in a clean way as it described in the documentation and my personal opinion is that it looks dirty to to this at all. Instead, what I like is to be able to do override this method via default vue-i18n config object. The syntax is pretty simple:
new VueI18n({
locale: 'pl', // set locale
getChoiceIndex(choice, choicesLength) {
// Custom pluralization code goes here
}
})
so when using nuxt-i18n module I can simply do:
modules: [ ['nuxt-i18n', {
locales: [...],
vueI18n: {
getChoiceIndex(choice, choicesLength) {
// Custom pluralization code goes here
}
}
}]]
I think such approach is much more cleaner to use!
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (3 by maintainers)
Top Results From Across the Web
The Ultimate Guide to Vue Localization with Vue I18n - Medium
We'll use getChoiceIndex() to override the VueI18n instance's method by the same name. getChoiceIndex() does the work of determining which ...
Read more >API references | Vue I18n
API references. # Extension of Vue. # Vue constructor options. # i18n. Type: I18nOptions. Component based localization option.
Read more >Vue i18n: Building a multi-language app with locale switcher
Vue i18n is a key process needed to localize your Vue apps and websites. Learn how to set up a Vue app with...
Read more >A B C D E F G H I J K L M N O P ...
return the object reference for an instance method to be called (we are still in the caller's frame). getCalleeThis(int) - Method in class...
Read more >Index (OfficeFloor 3.33.0 API)
Abstract functionality for overriding the System.getenv(String) values in tests. ... array will provide all Content-Type parsing available for the Object .
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No need to override
VueI18n.prototype.getChoiceIndex
. Updatenuxt
andvue-i18n
to latest version, and usepluralizationRules
option.plugins/i18n.js
nuxt.config.js
Ok so upon some further digging, the problem is not in vue-i18n but rather in nuxt-i18n. As you can see here, nuxt-i18n takes the vueI18n options and stringifies them using
JSON.stringify
. That causes the functions to be removed and just returns an objectpluralizationRules: {}
.So here’s a nice workaround. Instead of adding
pluralizationRules
withinvueI18n
options, you can add a plugin:and then you just have to register the plugin with
ssr: true
:That way it works for SSR as well 😃
Hope that helps. cc @fibigerg @AndrewBogdanovTSS