Files
mes-ui-d2/docs/zh/plugins/i18n.md
liyang 4bf4414757 no message
Former-commit-id: fa44e62cc25b58c8e3ea1608d619a80e5be1d398 [formerly fa44e62cc25b58c8e3ea1608d619a80e5be1d398 [formerly fa44e62cc25b58c8e3ea1608d619a80e5be1d398 [formerly fa44e62cc25b58c8e3ea1608d619a80e5be1d398 [formerly 36c19824b8471a64fc79448f387a53bf3846c9f5 [formerly 8bf2ad148e3d6f4b6fcf9b1113666872f51a2924]]]]]
Former-commit-id: 5b3c2d62929d06dcf6875bbcfe9c463acf694941
Former-commit-id: 41b9d7f61085f40a2167d67bf053a2dcfe823159
Former-commit-id: c5a5f3433498e95f9fdbbdf225612773c71b4e1c [formerly 6ab62d738b4e0605ff65e0a9dba72362269f2036]
Former-commit-id: 5d3a8fc8ec8de1fece491026ad143d0d31953aeb
Former-commit-id: f7740607d012c1c96f92dd56950ef983ffebad08
Former-commit-id: ba408cbe880ab3c7c0c098c4094dee42f93ef3d4
Former-commit-id: 960996e83cee4f35ff5bfd87e286176e3ef77533
Former-commit-id: 9445fd6b866e60c132f6dac34831b5f80ec03819
2018-06-20 14:00:45 +08:00

124 lines
2.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 多国语
多国语插件
::: tip
此文档仅限于演示如何在 `D2Admin` 中使用多国语言设置
:::
公用的语言设置建议放在 `src/i18n`
i18n 文件夹结构如下所示
```
|__index.js // 主文件
|__lang // 语言配置文件夹
| |__cn // 中文
| | |__index.js // 中文 公用配置
| |__ja // 日语
| | |__index.js // 日语 公用配置
| |__en // 英语
| | |__index.js // 英语 公用配置
```
`src/i18n/index.js` 中导入同级lang文件夹内的语言设置并导出一个新的 `VueI18n` 实例供 `main.js` 使用
``` js
import i18n from './i18n'
new Vue({
el: '#app',
store,
i18n, // 使用 i18n
router,
template: '<App/>',
components: { App }
})
```
## 使用
使用 `$t('路径')`
``` vue
<PageHeader
slot="header"
:title="`${$t('pub.pageHeader.demo')} 1`"
url="http://kazupon.github.io/vue-i18n/en/">
</PageHeader>
```
## 局部配置
有时候我们只希望在某个文件中配置这个组件的多国语言,如果所有的语言设置都放在 `d2-admin/src/i18n` 中会造成混乱,不易维护
`D2Admin` 已经替你安装好了 `vue-i18n-loader`,可以方便地在单文件组件中使用
示例
``` vue
<i18n src="./lang.json"></i18n>
<template>
<div>
<el-tag>{{$t('hello')}}</el-tag>
<p>{{$t('check.title')}}</p>
<el-checkbox-group v-model="check">
<el-checkbox label="a">{{$t('check.label.Beijing')}}</el-checkbox>
<el-checkbox label="b">{{$t('check.label.Tokyo')}}</el-checkbox>
<el-checkbox label="c">{{$t('check.label.NewYork')}}</el-checkbox>
</el-checkbox-group>
</div>
</template>
<script>
export default {
data () {
return {
check: ['a', 'b']
}
}
}
</script>
```
在同一文件夹下的 `lang.json`
``` json
{
"cn": {
"hello": "你好",
"check": {
"title": "请选择",
"label": {
"Beijing": "北京",
"Tokyo": "东京",
"NewYork": "纽约"
}
}
},
"en": {
"hello": "hello",
"check": {
"title": "Please choose",
"label": {
"Beijing": "Beijing",
"Tokyo": "Tokyo",
"NewYork": "NewYork"
}
}
},
"ja": {
"hello": "こんにちは",
"check": {
"title": "選択してください",
"label": {
"Beijing": "北京",
"Tokyo": "東京",
"NewYork": "ニューヨーク"
}
}
}
}
```
详细教程请查看官方文档,见此页右上角的链接