-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
76 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# 国际化 | ||
|
||
如果你使用的 vscode 开发工具,则推荐使用 [i18n Ally](https://marketplace.visualstudio.com/items?itemName=Lokalise.i18n-ally) 插件,安装了该插件后,你的代码内可以实时看到对应的语言内容。 | ||
|
||
## 使用 | ||
|
||
X-BUILD 已经帮你安装好了 i18n 插件,开箱即用,可以参考下面的简单示例: | ||
|
||
```vue | ||
<template> | ||
<form> | ||
<label>{{ t('language') }}</label> | ||
<select v-model="locale"> | ||
<option value="en">en</option> | ||
<option value="zh_CN">zh_CN</option> | ||
</select> | ||
</form> | ||
<p>{{ t('message.title') }}</p> | ||
</template> | ||
<script lang="ts" setup name="PageExample"> | ||
import { useI18n } from 'vue-i18n'; | ||
const { t, locale } = useI18n(); | ||
</script> | ||
``` | ||
|
||
## 语言文件 | ||
|
||
在 src/locales/lang/ 管理对应语言的文件。 | ||
|
||
如果你想新增语言,例如增加日语,你可以在此目录下创建 ja.ts,并对此语言进行配置。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { createI18n } from 'vue-i18n'; | ||
// eslint-disable-next-line camelcase | ||
import zh_CN from './lang/zh_CN'; | ||
import en from './lang/en'; | ||
|
||
const messages = { | ||
zh_CN, | ||
en, | ||
}; | ||
|
||
const i18n = createI18n({ | ||
legacy: false, | ||
locale: 'zh_CN', | ||
messages, | ||
}); | ||
|
||
export default i18n; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// src/i18n/language/en.ts | ||
export default { | ||
message: { | ||
title: 'hello', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default { | ||
message: { | ||
title: '你好', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters