优化更新
This commit is contained in:
@@ -1,23 +1,29 @@
|
||||
# 国际化
|
||||
|
||||
:::tip 说明
|
||||
当前项目仅支持中文界面,ElementPlus 使用中文语言包(`zh-cn`),所有界面文本直接硬编码在组件中。如需扩展多语言支持,可基于 vue-i18n 实现。
|
||||
当前项目仅支持中文界面,NaiveUI 使用中文语言包(`zhCN`),所有界面文本直接硬编码在组件中。如需扩展多语言支持,可基于 vue-i18n 实现。
|
||||
:::
|
||||
|
||||
## 当前状态
|
||||
|
||||
项目当前为中文单语言版本:
|
||||
|
||||
- ElementPlus 全局配置中文语言包:`app.use(ElementPlus, { locale: zhCn })`
|
||||
- 所有界面文本直接硬编码在组件中:`<el-button>添加岗位</el-button>`
|
||||
- NaiveUI 全局配置中文语言包:通过 `n-config-provider` 的 `locale` 属性设置 `zhCN`
|
||||
- 所有界面文本直接硬编码在组件中:`<n-button>添加岗位</n-button>`
|
||||
- 后端返回的 `msg` 字段为中文:`"操作成功"`、`"岗位名称不能重复"`
|
||||
|
||||
```vue
|
||||
<template>
|
||||
<el-button type="primary">添加岗位</el-button>
|
||||
<el-table-column label="岗位名称" prop="name" />
|
||||
<el-table-column label="创建时间" prop="createTime" />
|
||||
<n-button type="primary">添加岗位</n-button>
|
||||
<n-data-table :columns="columns" :data="data" />
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
const columns = [
|
||||
{ title: '岗位名称', key: 'name' },
|
||||
{ title: '创建时间', key: 'createTime' },
|
||||
];
|
||||
</script>
|
||||
```
|
||||
|
||||
## 扩展方案
|
||||
@@ -65,23 +71,26 @@ export default i18n;
|
||||
|
||||
```vue
|
||||
<template>
|
||||
<el-button type="primary">{{ $t('common.add') }}</el-button>
|
||||
<el-table-column :label="$t('position.name')" prop="name" />
|
||||
<n-button type="primary">{{ $t('common.add') }}</n-button>
|
||||
<n-data-table :columns="columns" :data="data" />
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { useI18n } from 'vue-i18n';
|
||||
const { t } = useI18n();
|
||||
const columns = [
|
||||
{ title: t('position.name'), key: 'name' },
|
||||
];
|
||||
</script>
|
||||
```
|
||||
|
||||
### ElementPlus 国际化
|
||||
### NaiveUI 国际化
|
||||
|
||||
```typescript
|
||||
import zhCn from 'element-plus/es/locale/lang/zh-cn';
|
||||
import en from 'element-plus/es/locale/lang/en';
|
||||
import { zhCN, dateZhCN } from 'naive-ui';
|
||||
|
||||
app.use(ElementPlus, { locale: zhCn });
|
||||
// 通过 n-config-provider 设置语言包
|
||||
// <n-config-provider :locale="zhCN" :date-locale="dateZhCN">
|
||||
```
|
||||
|
||||
:::tip 温馨提示
|
||||
@@ -90,4 +99,4 @@ app.use(ElementPlus, { locale: zhCn });
|
||||
|
||||
## 总结
|
||||
|
||||
当前项目为中文单语言版本,ElementPlus 使用中文语言包。如需扩展多语言支持,可基于 vue-i18n 实现前端国际化,配合 ElementPlus 内置语言包和后端消息 code 实现全链路多语言。
|
||||
当前项目为中文单语言版本,NaiveUI 使用中文语言包。如需扩展多语言支持,可基于 vue-i18n 实现前端国际化,配合 NaiveUI 内置语言包和后端消息 code 实现全链路多语言。
|
||||
|
||||
Reference in New Issue
Block a user