Files
mayfly-go/docs/frontend/i18n.md
2026-05-08 20:45:13 +08:00

46 lines
944 B
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.
---
trigger: always_on
---
# 国际化规范
## 文件组织
```
src/i18n/
├── zh-cn/
│ ├── common.ts
│ ├── system.ts
│ ├── ai.ts
│ └── ...
└── en/
├── common.ts
├── system.ts
└── ...
```
- 按模块拆分,每个业务模块一个文件
- 命名空间以模块名为根 key`system.account.name`
## 使用方式
```vue
<template>
<h1>{{ $t('system.account.name') }}</h1>
<el-button>{{ $t('common.save') }}</el-button>
</template>
<script setup>
import { useI18n } from 'vue-i18n';
const { t } = useI18n();
const message = t('common.success');
</script>
```
## 边界
-**Always**: 所有展示文本通过 `$t()``t()` 获取
-**Always**: 枚举的 label 必须是国际化 key
-**Always**: 新增模块时在 `zh-cn/``en/` 下同时创建语言文件
- 🚫 **Never**: 在组件中直接写中文/英文文本