-
-
Notifications
You must be signed in to change notification settings - Fork 861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vue.locale is not a function - Issue after upgrading to 3.0 #28
Comments
Thank you for your reporting!! Can you tell me the how to include vue-i18n script to your app enviroment please? |
I've the same error. I'm using it with vue-router. And i don't know why doesn't works. import VueI18n from 'vue-i18n'; and then Vue.use(VueI18n); with the others plugins. But inside my App component, if i tried to use Vue.locale i got that error. Any suggestions? ------------------ update I solve by put the locale setting before router.start. And then i can access to $t function inside the template. But inside from my other components i can't access to Global Vue.t |
Related kazupon/vue-validator#188 |
In my enviroment, I reproduced this issue. This issue occured when execute |
Can you paste a simple example about that ? |
installation example: import Vue from 'vue'
import App from './App.vue'
import VueI18n from 'vue-i18n'
import VueRouter from 'vue-router'
import { locales } from './locales'
Vue.use(VueRouter)
let Foo = Vue.extend({
template: '<p>This is foo!</p>'
})
let Bar = Vue.extend({
template: '<p>This is bar! {{ $t("message")}}</p>'
})
Vue.use(VueI18n)
Vue.config.lang = 'en'
Object.keys(locales).forEach(function (lang) {
Vue.locale(lang, locales[lang])
})
let router = new VueRouter()
router.map({
'/foo': {
component: Foo
},
'/bar': {
component: Bar
}
})
router.start(App, 'body') |
For me doens't works yet for the global function like Vue.t, if try to call inside another component. Btw i can use the $t function inside template. Thanks a lot man !! |
Thank you for your feedback! |
Sure. I'll try. import Vue from 'Vue'
import App from './components/App.vue'
import VueI18n from 'vue-i18n'
import VueRouter from 'vue-router'
import VueValidator from 'vue-validator'
import VueResource from 'vue-resource'
import infiniteScroll from 'vue-infinite-scroll'
import locales from './locales'
import config from './config'
import { configRouter } from './config/route-config'
Vue.use(VueRouter)
Vue.use(VueValidator)
Vue.use(VueResource)
Vue.use(infiniteScroll)
Vue.use(VueI18n)
const router = new VueRouter({
hashbang: true,
saveScrollPosition: true,
history: true
})
configRouter(router)
document.addEventListener('deviceready', function () {
Vue.config.lang = config.language();
Object.keys(locales).forEach(function (lang) {
Vue.locale(lang, locales[lang])
})
router.start(App, '#app')
}, false); I'm using vue with cordova, so i need to include route.start and the initialization of vue i18n inside deviceready, to access navigator.globalization.getPreferredLanguage function. And that's all! |
I have the same issue ( import Vue from 'vue';
import Search from './search.vue';
import VueI18n from 'vue-i18n';
$(document).foundation();
var locales = {
de: {
labels: {
fairs: "Messen"
}
},
en: {
labels: {
fairs: "Fairs"
}
}
};
Vue.use(VueI18n);
var documentLanguage = $('html').attr('lang');
Vue.config.lang = documentLanguage;
Object.keys(locales).forEach(function (lang) {
Vue.locale(lang, locales[lang]);
}); The line setting the locale strings ( var _vue = require('vue');
var _vue2 = _interopRequireDefault(_vue);
var _search = require('./search.vue');
var _search2 = _interopRequireDefault(_search);
var _vueI18n = require('vue-i18n');
var _vueI18n2 = _interopRequireDefault(_vueI18n);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
$(document).foundation();
var locales = {
de: {
labels: {
fairs: "Messen"
}
},
en: {
labels: {
fairs: "Fairs"
}
}
};
_vue2.default.use(_vueI18n2.default);
var documentLanguage = $('html').attr('lang');
_vue2.default.config.lang = documentLanguage;
Object.keys(locales).forEach(function (lang) {
_vue2.default.locale(lang, locales[lang]);
}); |
I'm seeing the same issue as the last commenter - simple Vue app, no router or anything, and the same Help? |
Same issue. Here is my main.js:
EDIT: Fixed by using the new init from 6.0.0-alpha1. |
Getting same issue with import Passport from './src/components/documents/Passport.vue'
import Form8 from './src/components/documents/Form8.vue'
import BootstrapVue from 'bootstrap-vue'
import Vue from 'vue'
import jQuery from 'jquery'
import VeeValidate from 'vee-validate'
import VueResource from 'vue-resource'
import VueI18n from 'vue-i18n'
Vue.use(BootstrapVue)
Vue.use(VeeValidate)
Vue.use(VueResource)
Vue.use(VueI18n)
Vue.config.lang = 'en'
Vue.locale('en', {test: 'test'})
Vue.component('passport', Passport)
Vue.component('form8', Form8)
jQuery(document).ready(function() {
new Vue({
el: '#vue-app',
data: {
identity: gon.identity,
residence: gon.residence,
countries: gon.countries
},
components: ['passport', 'form8']
})
}) |
@r00takaspin Try to use: import Passport from './src/components/documents/Passport.vue'
import Form8 from './src/components/documents/Form8.vue'
import BootstrapVue from 'bootstrap-vue'
import Vue from 'vue'
import jQuery from 'jquery'
import VeeValidate from 'vee-validate'
import VueResource from 'vue-resource'
import VueI18n from 'vue-i18n'
Vue.use(BootstrapVue)
Vue.use(VeeValidate)
Vue.use(VueResource)
Vue.use(VueI18n)
var i18n = new VueI18n({
locale: 'en',
messages: {test: 'test'}
})
Vue.component('passport', Passport)
Vue.component('form8', Form8)
jQuery(document).ready(function() {
new Vue({
el: '#vue-app',
data: {
identity: gon.identity,
residence: gon.residence,
countries: gon.countries
},
components: ['passport', 'form8'],
i18n: i18n
})
}) |
@yageek thanks a lot, it really works fine. I just tried to implement another example. |
has the same question in vue2 |
@r00takaspin @yageek , thanks your example, but i still can't understand how to input multi-locale to i18n instance . And how to render string that i expected in html template. |
@warcryDoggie If you have set up everything like the code upwards:
{{ $t("keyPath") }}
this.$i18n.t('keyPath') |
i just move vue-i18n to version 5.0.3 |
Beta is beta
|
@yageek thanks, your suggestion worked. 👍 |
I had the same issue, and then I figured out that the version that npm installs is the 6.0.0-alpha. Why is put a alpha as the last version in npm repository? I think is the main reason this issue is opened. |
Can confirm,
The error goes away if I manually force in package.json |
Probably you don't have to downgrade to version |
This is indeed frustrating. We tried today to go live with a production and then run into one submodule that caused a complete break.. this one. The breaking changes are indeed breaking. Can confirm that ))) This no longer works, and there seems no simple migration info? What is the replacement for Vue.locale ? var VueI18n = require('vue-i18n') // https://kazupon.github.io/vue-i18n/
Vue.use(VueI18n)
// Load files from lang folder
const loadLocales = [
{ "isocode": "en", "language": "English" },
{ "isocode": "nl", "language": "Nederlands" }
]
loadLocales.forEach(function (lang) {
// loading files such as en.js and nl.js
let langObj = require("../lang/" + lang.isocode)
Vue.locale(lang.isocode, langObj)
}) |
I'm having the same issue - I'm using v6.1.0. |
I managed to get this working in two steps. 1 - in import Vue from 'vue'
/** LANGUAGES / LOCALES */
import VueI18n from 'vue-i18n' // https://kazupon.github.io/vue-i18n/
Vue.use(VueI18n)
// Load files from lang folder
const loadLocales = [
{ "isocode": "en", "language": "English" },
{ "isocode": "nl", "language": "Nederlands" }
]
let messages = {}
loadLocales.forEach(function (lang) {
// loading files such as en.js and nl.js
let langObj = require("../lang/" + lang.isocode)
messages[lang.isocode] = langObj
})
// set browser language Footer component can change the language
let lang = Vue.config.lang || window.navigator.userLanguage || window.navigator.language || "en"
// this seems to have become obsolete in vue-i18n / v6:
Vue.config.lang = lang.substr(0, 2) // "en-US" >> "en"
const i18n = new VueI18n({
locale: Vue.config.lang, // set locale
fallbackLocale: 'en',
silentTranslationWarn: false,
messages // set locale messages
})
export default i18n 2- and in // Language and locales
import i18n from "./assets/js/locales"
// Router for serving url's
import router from './assets/js/router'
/** MOUNT THE APP */
new Vue({
router,
i18n,
extends: {
template: '<div id="app"><router-view></router-view></div>'
}
}).$mount('#app') I have created another ticket for the failing |
I mentioned in #148, Vue.config.lang is deprecated in v6 or later. |
I'm getting
Unknown TypeError: Vue.locale is not a function
And in my locales file I have like I had in 2.*:
The text was updated successfully, but these errors were encountered: