vue.js - 使用 i18n 翻译 vue-router 中的元标记
问题描述
我不知道如何在 vue.router 中使用 i18n 来翻译用于我的面包屑的元标记
main.js
import vuexI18n from 'vuex-i18n';
Vue.use(vuexI18n.plugin, store);
const i18n = Vue.i18n
import es_es from '@/assets/langs/es_es';
import en_us from '@/assets/langs/en_us';
i18n.add('es_es', es_es)
i18n.add('en_us', en_us)
i18n.set('en_us')
路由器.js
import vuexI18n from 'vuex-i18n'
Vue.use(Router)
Vue.use(vuexI18n.plugin, store)
const i18n = Vue.i18n
尝试翻译的路线的关键
{
path: '/clientes/nuevo',
name: 'CustomersNew',
beforeEnter: (to, from, next) => {
Auth(to, from, next);
CheckPermission(to, from, next, "customers@add_customer");
},
component: CustomersNew,
meta: {
breadcrumb: {
title: Vue.i18n.translate('customers.title'),
links: [ "Customers", "new"]
}
}
}
任何模板中使用的任何翻译都可以很好地翻译。
解决方案
您可以将密钥作为字符串传递并直接在面包屑组件中进行翻译,而不是尝试直接在路由器上进行翻译
{
path: '/clientes/nuevo',
name: 'CustomersNew',
beforeEnter: (to, from, next) => {
Auth(to, from, next);
CheckPermission(to, from, next, "customers@add_customer");
},
component: CustomersNew,
meta: {
breadcrumb: {
title: "key.to.translate.as.string',
links: [ "Customers", "new"]
}
}
}
在组件中,一如既往地翻译。
推荐阅读
- c - 我怎样才能在OK之前添加消息?
- javascript - 将注册表单发送到 php 并通过 javascript 进行验证
- arrays - 数组数组的运行时数组赋值
- python - 什么 python 内置函数可以将一些函数应用于列表的每个元素?
- sql - 如何加入这些表以从客户那里获得独特的产品描述?
- django - 从内联表单集的查询集中排除元素
- python - 如何只打印包含某个字符串的文件中的行?
- python - 当我尝试在 python 中将 pandas 保存为 excel 文件时出错
- python - 如何删除一个numpy数组:追逐内存增长
- php - 在 EasyAdmin 3.x 上使用验证组