Vue.extend does not accept a VueI18n class instance as i18n option
See original GitHub issuevue & vue-i18n version
2.4.2 & 7.0.5 (using dist from master in fiddle)
Reproduction Link
Minimal example http://jsfiddle.net/Ly55ew8m/2/
Our use case is not represented in that fiddle, see below.
Steps to reproduce
Passing a VueI18n
instance to Vue.extend
is ignored, only a plain old i18n
options object works.
In fiddle just comment and un-comment the relevant lines
What is Expected?
If a class instance would work, we could keep (and export) a reference to the instance and import it in other parts of the application (like vuex actions) to control vue-i18n
, i.e. locale switch.
What is actually happening?
We can not use a class instance so we have to add the locale switch logic inside the Vue.extend
options: i.e. watch a vuex
getter for current language and switch language through this.$i18n.locale
.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:10 (5 by maintainers)
Top Results From Across the Web
API references | Vue I18n
API references. # Extension of Vue. # Vue constructor options. # i18n. Type: I18nOptions. Component based localization option.
Read more >Breaking Changes - Vue I18n
Vue I18n is no longer a class but a set of functions. Instead of writing new VueI18n() , you now have to call...
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 >Use I18n translation messages from SFC when using Vue ...
Just import and add i18n instance to the new component instance const CopyToClipboard = Vue.extend(copyToClipboard); $(event.
Read more >Advanced usage - Vuelidate
You can still define your validation rules as part of the Options API. ... do not have $ prefixed, this is intentional, as...
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
@kimuraz to get around this issue you must pass the i18n object into the constructor not the extend call.
@kazupon I’ve found the reason why
Vue.extend
cannot work, It’s becauseVue.config.optionMergeStrategies.i18n
useVue.config.optionMergeStrategies.methods
, which makes i18n instance loses his__proto__
, so theoptions.i18n instanceof VueI18n
becomes false. Will vue-i18n supportVue.extend({i18n})
? If yes, I can fix this problem.