有什么办法可以让iview2兼容[email protected]+ ?
element有相应的兼容方法,iview2有没有?
现在vue-i18n已经出到7.0了
iview2只支持5.X,6.X以上版本就报错了。现在项目里用的是6.X以上版本做的多语言组件,实在不想改动这部分代码降级到5.X
delete the code after
iview/src/locale/index.js @ line 16
Vue.locale(
Vue.config.lang,
deepmerge(lang, Vue.locale(Vue.config.lang) || {}, { clone: true })
);
iview/dist/iview.js @ line 1753
_vue2.default.locale(_vue2.default.config.lang, (0, _deepmerge2.default)(lang, _vue2.default.locale(_vue2.default.config.lang) || {}, { clone: true }));
main.js
import Vue from 'vue'
import iView from 'iview'
import VueI18n from 'vue-i18n';
import 'iview/dist/styles/iview.css'
import usLang from 'iview/src/locale/lang/en-US';
import cnLang from 'iview/src/locale/lang/zh-CN';
Vue.use(iView)
Vue.use(VueI18n);
Vue.config.productionTip = false
const messages = {
'en-US': {
message: {
hello: 'hello my friend'
}
},
'zh-CN': {
message: {
hello: '你好'
}
}
}
const mixLang = {
'en-US': {},
'zh-CN': {}
}
mixLang['en-US'] = Object.assign(messages['en-US'], usLang)
mixLang['zh-CN'] = Object.assign(messages['zh-CN'], cnLang)
const i18n = new VueI18n({
locale: 'zh-CN',
messages: mixLang
});
new Vue({
el: '#app',
i18n,
template: '<App/>',
components: { App }
})
the project can run,the i18n version is 7.0.1
Thanks @wocanbe , app is running well when removed the codes, but I still get an error when open a date-picker component :
VM27654:27 TypeError: Cannot read property '_t' of undefined
at Vue$3.Vue.$t (eval at <anonymous> (app.js:3866), <anonymous>:105:16)
at Vue$3.i18nHandler (eval at <anonymous> (app.js:3765), <anonymous>:1610:24)
at Vue$3.t (eval at <anonymous> (app.js:3765), <anonymous>:1615:29)
at Vue$3.t (eval at <anonymous> (app.js:3765), <anonymous>:682:30)
at Vue$3.boundFn [as t] (eval at <anonymous> (app.js:769), <anonymous>:165:14)
at Vue$3.yearLabel (eval at <anonymous> (app.js:3765), <anonymous>:9675:30)
at Watcher.get (eval at <anonymous> (app.js:769), <anonymous>:2779:25)
at Watcher.evaluate (eval at <anonymous> (app.js:769), <anonymous>:2879:21)
at Proxy.computedGetter (eval at <anonymous> (app.js:769), <anonymous>:3133:17)
at Proxy.render (eval at <anonymous> (app.js:3765), <anonymous>:19988:26)
By the way, we can just define an empty locale method like this instead of modifying origin codes:
Vue.locale = function () {}
import Vue from 'vue';
import VueI18n from 'vue-i18n';
import iView from 'iview';
import en from './en';
import zh from './zh_CN';
import zhLocale from 'iview/src/locale/lang/zh-CN';
import enLocale from 'iview/src/locale/lang/en-US';
Vue.config.lang = 'zh_CN';
Vue.use(VueI18n);
const messages = {
en: Object.assign(en, enLocale),
zh_CN: Object.assign(zh, zhLocale)
}
const i18n = new VueI18n({
locale: Vue.config.lang,
fallbackLocale: 'en',
messages
})
Vue.use(iView, {
i18n: function(path, options) {
let value = i18n.t(path, options);
if (value !== null && value !== undefined) return value;
return '';
}
});
const app = new Vue({
i18n,
render: h => h(App),
}).$mount('#app');
这是我参考Elementui实现的,先合并语言包,然后自定义iView的i18nHandler
临时加一个空方法避免出错了,我用了vue-i18n,没必要使用iview 的国际化了
Vue.locale = (locale) => {
};
原来如此,我一直以为是我的code不对
@klgd 你的方法兼容了iview和i18n‘7.0.5’。666
好奇为什么iview 不更新这个支持呢
非常感谢 @klgd 的解决方法 iview的作者可以把国际化做成可插拔的 iview本身vue框架不应该依赖vue-i18n的版本 这样不利于iview框架的发展
@brandonccx 我也出现同样的问题,你的解决了吗?
你们都解决了吗?总是有各种问题
when can we support [email protected]
@icarusion
Thanks @wocanbe , app is running well when removed the codes, but I still get an error when open a date-picker component :
VM27654:27 TypeError: Cannot read property '_t' of undefined at Vue$3.Vue.$t (eval at <anonymous> (app.js:3866), <anonymous>:105:16) at Vue$3.i18nHandler (eval at <anonymous> (app.js:3765), <anonymous>:1610:24) at Vue$3.t (eval at <anonymous> (app.js:3765), <anonymous>:1615:29) at Vue$3.t (eval at <anonymous> (app.js:3765), <anonymous>:682:30) at Vue$3.boundFn [as t] (eval at <anonymous> (app.js:769), <anonymous>:165:14) at Vue$3.yearLabel (eval at <anonymous> (app.js:3765), <anonymous>:9675:30) at Watcher.get (eval at <anonymous> (app.js:769), <anonymous>:2779:25) at Watcher.evaluate (eval at <anonymous> (app.js:769), <anonymous>:2879:21) at Proxy.computedGetter (eval at <anonymous> (app.js:769), <anonymous>:3133:17) at Proxy.render (eval at <anonymous> (app.js:3765), <anonymous>:19988:26)By the way, we can just define an empty locale method like this instead of modifying origin codes:
Vue.locale = function () {}
你解决了吗 一选择日期框就报错的问题
Most helpful comment
这是我参考Elementui实现的,先合并语言包,然后自定义iView的i18nHandler