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.

Vue.extend does not accept a VueI18n class instance as i18n option

See original GitHub issue

vue & 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:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

9reactions
rikbrowningcommented, Jan 22, 2018

@kimuraz to get around this issue you must pass the i18n object into the constructor not the extend call.

const Constructor = Vue.extend(SmallComponent);
const vm = new Constructor({i18n}).$mount()
0reactions
jaredzhu1993commented, Aug 31, 2018

@kazupon I’ve found the reason why Vue.extend cannot work, It’s because Vue.config.optionMergeStrategies.i18n use Vue.config.optionMergeStrategies.methods, which makes i18n instance loses his __proto__, so the options.i18n instanceof VueI18n becomes false. Will vue-i18n support Vue.extend({i18n})? If yes, I can fix this problem.

Read more comments on GitHub >

github_iconTop 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 >

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