Hi,
I have just copy the basic example in the Getting Started section. But I get this error message each time from this file : vue-i18n.esm.js
2.1.10, 6.1.1
import VueI18n from 'vue-i18n';
import Locales from './vue-i18n-locales.generated.js';
const messages = {
en: {
message: {
hello: 'hello world'
}
},
ja: {
message: {
hello: 'γγγ«γ‘γ―γδΈη'
}
}
}
// Create VueI18n instance with options
const i18n = new VueI18n({
locale: 'ja', // set locale
messages, // set locale messages
});
And each time I got the same error message for this code part
VueI18n.prototype._initVM = function _initVM (data) {
var silent = Vue.config.silent;
Vue.config.silent = true;
this._vm = new Vue({ data: data });
Vue.config.silent = silent;
};
Any idea ? Thanks for your help.
Thank you for your feedback!
Could you provide a minimum reproruduce code with JSFiddle or JSBin or other please?
Hi,
I just make another test on JSFiddle everything work fine. I will just check my config because I work with laravel-elixir-vue-2 and maybe the problem came from here.
Hi @gmarineau
you have to do ".use" before create i18n instance:
import Vue from 'vue';
import VueI18n from 'vue-i18n';
import Locales from './vue-i18n-locales.generated.js';
// here
Vue.use(VueI18n)
const messages = {
en: {
message: {
hello: 'hello world'
}
},
ja: {
message: {
hello: 'γγγ«γ‘γ―γδΈη'
}
}
}
// Create VueI18n instance with options
const i18n = new VueI18n({
locale: 'ja', // set locale
messages, // set locale messages
});
@dbalas OK thanks. I will make a test and give you a feedback.
hello all, I still cant make it work :(
"vue": "^2.3.3",
"vue-i18n": "^6.1.3"
`window.VueI18n = require(\'vue-i18n\');
window.Locales = require('./vue-i18n-locales.generated.js');
Vue.use(VueI18n);
const i18n = new VueI18n({
locale: 'it',
messages: Locales
});`
TypeError: VueI18n is not a constructor[Learn More]
Close (in-activity)
Ho god thank, i lost 2 hours on this issue -_-"
I still have this problem in 7.7.0 if I try to put this configuration in an isolated file, since I have to call Vue.use (VueI18n) in this configuration file and also in my entry file (application.js). That's where the problem comes from:
If I do not call Vue.use(VueI18n) again on my application.js, it triggers the following error:
Property or method "$t" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. [...]
If I call Vue.use(VueI18n) again on my application.js, it triggers the following warning:
[vue-i18n] already installed.
Property or method "$t" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. [...]
I was getting the same error. I had this
Vue.use(Framework7Vue, Framework7, VueI18n);
then I changed it so that VueI18n is used separately and now it works..
Vue.use(Framework7Vue, Framework7);
Vue.use(VueI18n);
Get the same issue while trying to export i18n object into main file
not work
`
import {i18n} from './i18n';
new Vue({
router: createRouter(),
i18n,
components: {
'navbar': navbarComponent
},
}).$mount('#app-main');`
I'm facing with the same issue. My code: https://pastebin.com/gCxHqjAd
Vue version: ^2.5.2
VueI18n version: ^8.1.0
Having the same issue.
"vue": "^2.5.0",
"vue-i18n": "^8.5.0",
The issue can be tracked down to
VueI18n.prototype._initVM = function _initVM (data) {
var silent = Vue.config.silent;
Vue.config.silent = true;
this._vm = new Vue({ data: data });
Vue.config.silent = silent;
};
Where Vue is apparently undefined?
Just installed it into the basic setup provided by Vue-cli 3, same code as shown by @dbalas.
@kazupon
I fixed it by moving my imports from a different file (which also uses Vue to use Vue.use(VueI18n);).
This resolved the error on my application.
im using nuxt 2.8.1 with i18n 8.15.0 - got the same error
@kazupon I need to use VueI18n without installation (e.g., Vue.use(VueI18n)). How can I achieve it?
The following variable names are only used to explain the issue and how to solve it
import Vue from 'vue'
import VueI18n from 'vue-i18n'
// Adds imported VueI18n functionality to Vue
Vue.use(VueI18n)
// Creates an instance of VueI18n that must be inserted into the vue object creation
var languagesData = { en: { 'testmsg': 'This is a test msg!' } }
var i18nInstance = new VueI18n({
locale: 'en',
fallbackLocale: 'en',
messages: languagesData
})
// Vue object instance creation
var vue = new Vue({
render: h => h(App),
i18nInstance,
})
// Then you can display it {{ $t('testmsg') }}
Most helpful comment
Hi @gmarineau
you have to do ".use" before create i18n instance: