当前位置:网站首页>VXE-Table融合多语言
VXE-Table融合多语言
2022-08-05 07:11:00 【Teln_小凯】
VXE官方的多语言教程是这样的:
vxe-table v4https://vxetable.cn/#/table/start/i18n但是,系统中已经有自己的多语言了怎么办?
下面是自定义的i18n根VXE的融合过程:
1、引入插件
npm install vue-i18n
2、创建i18n.js
import Vue from 'vue'
import VueI18n from 'vue-i18n'
//this.$i18n.locale // 通过切换locale的值来实现语言切换
//window.vm.$i18n.t('lang.我的网站名') 主要为了在index页面使用多语言
//html {
{$t('lang.test')}}
//js调用this.$t('lang.test')
//自己的框架里面所用的多语言
function initI18n() {
Vue.use(VueI18n)
let i18nOptions = {
locale: 'CN', // 语言标识
fallbackLocale: 'CN',//没有英文的时候默认中文语言
silentFallbackWarn: true,//抑制警告
messages: {
'CN': require('./locale/zh.js'), // 中文语言包
'US': require('./locale/en.js') // 英文语言包
}
}
return new VueI18n(i18nOptions)
}
//获取系统定义的语言
function getLangs() {
return [
{ Key: "CN", Name: "简体中文" },
{ Key: "US", Name: "English" },
];
}
export default{ initI18n, getLangs }
3、多语言文件
这里把vxe的文件拷贝进来就行
4、main.js里面引用
//多语言
import langs from '@/lang/i18n.js'
const i18n = langs.initI18n();
//vxeTable
import VXETable from 'vxe-table'
import 'vxe-table/lib/style.css'
// 对组件内置的提示语进行国际化翻译
VXETable.setup({i18n: (key, args) => i18n.t(key, args)})
Vue.use(VXETable)
/* window.vm.$i18n.t('lang.我的网站名') 主要为了在index页面使用多语言 */
window.vm = new Vue({
el: '#app',
router, store, i18n,
components: { App },
template: '<App/>'
})
5、多语言切换功能核心方法
//设置多语言
setLanguage(lang) {
// 对组件内置的提示语进行国际化翻译 vxe的
VXETable.setup({i18n: (key, args) => this.$i18n.t(key, args)})
//自定义的
this.$i18n.locale = lang;
//插件自带的
switch (lang) {
case "CN":
this.locale =
require("ant-design-vue/es/locale-provider/zh_CN").default;
break;
case "US":
default:
this.locale =
require("ant-design-vue/es/locale-provider/en_US").default;
break;
}
},
边栏推荐
- 七夕?编程?
- 游戏模拟器成了外挂帮凶,灰产对抗再升级
- Re regular expressions
- Flink Learning 11: Flink Program Parallelism
- 693. 行程排序
- MySQL:order by排序查询,group by分组查询
- 2006年星座运势全解-巨蟹
- 关于MP3文件中找不到TAG标签的问题
- After working for 3 years, I recalled the comparison between the past and the present when I first started, and joked about my testing career
- 配合屏幕录像专家,又小又清晰!
猜你喜欢
随机推荐
JS实现从照片中裁切自已的肖像
3555. 二叉树
RK3568环境安装
Vulnhub靶机:HA_ NARAK
IO process thread -> communication between processes -> day7
"Automatic Data Collection Based on R Language"--Chapter 3 XML and JSON
Promise (3) async/await
Using printf function in STM32
Modeling of the MAYA ship
配合屏幕录像专家,又小又清晰!
PCI Pharma Services Announces Multi-Million Dollar Expansion of UK Manufacturing Facility to Meet Growing Demand for Global High Potency Drug Manufacturing Services to Support Oncology Treatment
re正则表达式
【win7】NtWaitForKeyedEvent
RK3568 environment installation
Hash 这些知识你也应该知道
线性代数对角化
binary search tree problem
Game Thinking 19: Multi-dimensional calculation related to games: point product, cross product, point-line-surface distance calculation
Mysql为什么 建立数据库失败
C-Eighty seven(背包+bitset)