i18n.md
September 19, 2025 · View on GitHub
国际化
AirPower-Web 基于 @airpower/i18n 实现国际化支持,提供统一的多语言解决方案。
WebI18n 语言包
WebI18n 类定义了 Web 端的默认语言包,包含系统中常用的文本。
内置文本
| 属性 | 默认值(中文) | 说明 |
|---|---|---|
| ID | 'ID' | ID字段 |
| Detail | '详情' | 详情按钮 |
| Update | '修改' | 修改按钮 |
| Disable | '禁用' | 禁用按钮 |
| Enable | '启用' | 启用按钮 |
| Delete | '删除' | 删除按钮 |
| Add | '添加' | 添加按钮 |
| Confirm | '确定' | 确定按钮 |
| Cancel | '取消' | 取消按钮 |
表单相关
| 属性 | 默认值(中文) | 说明 |
|---|---|---|
| SelectPlease | '请选择' | 下拉选择提示 |
| ConfirmPlease | '请确认' | 确认提示 |
| ConfirmToDisable | '是否确认禁用当前选择的数据?' | 禁用确认提示 |
| ConfirmToEnable | '是否确认启用当前选择的数据?' | 启用确认提示 |
| ConfirmToDelete | '是否确认删除当前选择的数据?' | 删除确认提示 |
上传相关
| 属性 | 默认值(中文) | 说明 |
|---|---|---|
| UploadError | '上传失败' | 上传失败提示 |
| UploadSuccess | '上传成功' | 上传成功提示 |
| ClickHereToUpload | '点击或拖到此处上传' | 上传区域提示 |
| FileSizeLimited | '上传的文件过大' | 文件过大提示 |
| FileTypeNotSupported | '上传的文件暂不支持' | 文件类型不支持提示 |
使用方式
在代码中使用
import {WebI18n} from '@airpower/web'
// 直接访问语言包中的文本
console.log(WebI18n.Instance.Add) // 输出: 添加
在模板中使用
<template>
<AButton primary icon="ADD">
{{ WebI18n.Instance.Add }}
</AButton>
<ElMessageBox
:title="WebI18n.Instance.Confirm"
:message="WebI18n.Instance.ConfirmToDelete"
confirmButtonText="WebI18n.Instance.Confirm"
cancelButtonText="WebI18n.Instance.Cancel"
/>
</template>
<script setup>
import {WebI18n} from '@airpower/web'
</script>
自定义语言包
可以通过继承 WebI18n 类来创建自定义语言包:
import {WebI18n} from '@airpower/web'
export class CustomI18n extends WebI18n {
// 覆盖原有文本
Add = '新增'
Update = '编辑'
// 添加新的文本
CustomText = '自定义文本'
}
// 设置为当前语言包
WebI18n.Instance = new CustomI18n()
多语言切换
import {I18n} from '@airpower/i18n'
// 切换到英文
I18n.setLocale('en')
// 切换到中文
I18n.setLocale('zh')