@yh-ui/locale 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +37 -164
- package/dist/runtime.cjs +19 -0
- package/dist/runtime.d.ts +3 -0
- package/dist/runtime.mjs +2 -0
- package/package.json +3 -2
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,208 +1,81 @@
|
|
|
1
1
|
# @yh-ui/locale
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
<img src="https://raw.githubusercontent.com/1079161148/yh-ui/main/docs/public/logo.svg" width="100" height="100" alt="YH-UI Logo">
|
|
5
|
-
</p>
|
|
3
|
+
YH-UI 的语言包和国际化类型定义。它把组件文案、表格工具栏、日期时间、上传、AI 组件、业务组件等文本收敛到统一结构,方便在 Vue、Nuxt 和独立组件中复用。
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
[i18n Guide](https://1079161148.github.io/yh-ui/guide/i18n) | [Releases](https://github.com/1079161148/yh-ui/releases)
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
67 种语言 · 开箱即用 · 按需加载 · 动态切换 · 完整类型推导
|
|
11
|
-
</p>
|
|
7
|
+
## Highlights
|
|
12
8
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
<img src="https://img.shields.io/npm/dm/@yh-ui/locale.svg?style=flat-square&colorB=409eff" alt="npm downloads">
|
|
19
|
-
</a>
|
|
20
|
-
<a href="https://github.com/1079161148/yh-ui/blob/main/LICENSE">
|
|
21
|
-
<img src="https://img.shields.io/npm/l/@yh-ui/locale.svg?style=flat-square" alt="license">
|
|
22
|
-
</a>
|
|
23
|
-
</p>
|
|
9
|
+
- 覆盖 67 个语言文件,包含中文、英文、日文、韩文、德文、法文、西班牙文、葡萄牙文、俄文、阿拉伯文等常见业务语言。
|
|
10
|
+
- 每个语言包独立导出,可按需导入,避免把所有语言都打进业务包。
|
|
11
|
+
- 类型完整:`Language` 描述了组件库内所有可翻译字段,便于补充、覆盖和校验自定义语言。
|
|
12
|
+
- 覆盖面细:基础组件、Table、Upload、DatePicker、AI 组件、电商业务组件、地址解析、甘特图等都有对应文案结构。
|
|
13
|
+
- SSR 安全:语言包是纯数据导出,不依赖浏览器环境。
|
|
24
14
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
## ✨ 特性
|
|
28
|
-
|
|
29
|
-
- 🌍 **67 种语言** — 业内最全的 Vue 组件库语言支持(对比:Element Plus 43 种,Naive UI 25 种)
|
|
30
|
-
- 📦 **按需加载** — 每个语言包独立文件,只打包使用的语言
|
|
31
|
-
- ⚡ **运行时切换** — 基于 Vue 响应式系统,切换语言无需刷新页面
|
|
32
|
-
- 🔒 **完整类型推导** — `t()` 翻译函数支持 key 类型检查,防止拼写错误
|
|
33
|
-
- 🌐 **SSR 兼容** — 可在 Nuxt 3 服务端正确渲染
|
|
34
|
-
|
|
35
|
-
---
|
|
36
|
-
|
|
37
|
-
## 📦 安装
|
|
15
|
+
## Install
|
|
38
16
|
|
|
39
17
|
```bash
|
|
40
|
-
# pnpm(推荐)
|
|
41
18
|
pnpm add @yh-ui/locale
|
|
42
|
-
|
|
43
|
-
# npm
|
|
44
|
-
npm install @yh-ui/locale
|
|
45
19
|
```
|
|
46
20
|
|
|
47
|
-
|
|
21
|
+
通常你也可以直接通过 `@yh-ui/yh-ui` 使用内置导出的语言包。
|
|
48
22
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
## 🔨 快速开始
|
|
52
|
-
|
|
53
|
-
### 在主应用中配置
|
|
23
|
+
## Usage
|
|
54
24
|
|
|
55
25
|
```ts
|
|
56
26
|
import { createApp } from 'vue'
|
|
57
27
|
import YhUI from '@yh-ui/yh-ui'
|
|
58
|
-
import '@yh-ui/
|
|
59
|
-
import zhCN from '@yh-ui/locale/lang/zh-CN'
|
|
28
|
+
import zhCn from '@yh-ui/locale/lang/zh-cn'
|
|
60
29
|
import App from './App.vue'
|
|
61
30
|
|
|
62
|
-
|
|
63
|
-
app.use(YhUI, { locale: zhCN })
|
|
64
|
-
app.mount('#app')
|
|
31
|
+
createApp(App).use(YhUI, { locale: zhCn }).mount('#app')
|
|
65
32
|
```
|
|
66
33
|
|
|
67
|
-
|
|
34
|
+
## With ConfigProvider
|
|
68
35
|
|
|
69
36
|
```vue
|
|
70
37
|
<script setup lang="ts">
|
|
71
38
|
import { ref } from 'vue'
|
|
72
|
-
import { YhConfigProvider } from '@yh-ui/
|
|
73
|
-
import
|
|
74
|
-
import
|
|
75
|
-
import jaJP from '@yh-ui/locale/lang/ja'
|
|
76
|
-
import type { Language } from '@yh-ui/locale'
|
|
39
|
+
import { YhConfigProvider } from '@yh-ui/components'
|
|
40
|
+
import zhCn from '@yh-ui/locale/lang/zh-cn'
|
|
41
|
+
import en from '@yh-ui/locale/lang/en'
|
|
77
42
|
|
|
78
|
-
const
|
|
79
|
-
const currentLocale = ref<Language>(zhCN)
|
|
43
|
+
const locale = ref(zhCn)
|
|
80
44
|
</script>
|
|
81
45
|
|
|
82
46
|
<template>
|
|
83
|
-
<YhConfigProvider :locale="
|
|
84
|
-
|
|
85
|
-
<YhTable :data="data" :columns="columns" />
|
|
86
|
-
<YhPagination :total="100" />
|
|
47
|
+
<YhConfigProvider :locale="locale">
|
|
48
|
+
<YhButton @click="locale = en">English</YhButton>
|
|
87
49
|
<YhDatePicker />
|
|
50
|
+
<YhTable :data="rows" :columns="columns" />
|
|
88
51
|
</YhConfigProvider>
|
|
89
|
-
|
|
90
|
-
<div>
|
|
91
|
-
<button @click="currentLocale = localeMap['zh-CN']">中文</button>
|
|
92
|
-
<button @click="currentLocale = localeMap['en']">English</button>
|
|
93
|
-
<button @click="currentLocale = localeMap['ja']">日本語</button>
|
|
94
|
-
</div>
|
|
95
52
|
</template>
|
|
96
53
|
```
|
|
97
54
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
```ts
|
|
101
|
-
// nuxt.config.ts
|
|
102
|
-
export default defineNuxtConfig({
|
|
103
|
-
modules: ['@yh-ui/nuxt'],
|
|
104
|
-
yhUI: {
|
|
105
|
-
locale: 'zh-CN' // 设置默认语言
|
|
106
|
-
}
|
|
107
|
-
})
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
---
|
|
111
|
-
|
|
112
|
-
## 🌍 支持语言列表(67 种)
|
|
113
|
-
|
|
114
|
-
| 语言 | 导入路径 | 语言代码 |
|
|
115
|
-
| ---------------- | -------------------------- | -------- |
|
|
116
|
-
| 简体中文 | `@yh-ui/locale/lang/zh-CN` | `zh-CN` |
|
|
117
|
-
| 繁體中文 | `@yh-ui/locale/lang/zh-TW` | `zh-TW` |
|
|
118
|
-
| English | `@yh-ui/locale/lang/en` | `en` |
|
|
119
|
-
| 日本語 | `@yh-ui/locale/lang/ja` | `ja` |
|
|
120
|
-
| 한국어 | `@yh-ui/locale/lang/ko` | `ko` |
|
|
121
|
-
| Français | `@yh-ui/locale/lang/fr` | `fr` |
|
|
122
|
-
| Deutsch | `@yh-ui/locale/lang/de` | `de` |
|
|
123
|
-
| Español | `@yh-ui/locale/lang/es` | `es` |
|
|
124
|
-
| Português | `@yh-ui/locale/lang/pt` | `pt` |
|
|
125
|
-
| Italiano | `@yh-ui/locale/lang/it` | `it` |
|
|
126
|
-
| Русский | `@yh-ui/locale/lang/ru` | `ru` |
|
|
127
|
-
| العربية | `@yh-ui/locale/lang/ar` | `ar` |
|
|
128
|
-
| हिन्दी | `@yh-ui/locale/lang/hi` | `hi` |
|
|
129
|
-
| Türkçe | `@yh-ui/locale/lang/tr` | `tr` |
|
|
130
|
-
| Polski | `@yh-ui/locale/lang/pl` | `pl` |
|
|
131
|
-
| Nederlands | `@yh-ui/locale/lang/nl` | `nl` |
|
|
132
|
-
| Svenska | `@yh-ui/locale/lang/sv` | `sv` |
|
|
133
|
-
| ภาษาไทย | `@yh-ui/locale/lang/th` | `th` |
|
|
134
|
-
| Tiếng Việt | `@yh-ui/locale/lang/vi` | `vi` |
|
|
135
|
-
| Bahasa Indonesia | `@yh-ui/locale/lang/id` | `id` |
|
|
136
|
-
| ... | ... | 共 67 种 |
|
|
137
|
-
|
|
138
|
-
查看完整列表:[docs/guide/i18n](https://1079161148.github.io/yh-ui/guide/i18n)
|
|
139
|
-
|
|
140
|
-
---
|
|
141
|
-
|
|
142
|
-
## 🔌 在自定义 Hook 中使用
|
|
143
|
-
|
|
144
|
-
```ts
|
|
145
|
-
import { useLocale } from '@yh-ui/hooks'
|
|
146
|
-
|
|
147
|
-
const { t, locale } = useLocale()
|
|
148
|
-
|
|
149
|
-
// 获取翻译文本
|
|
150
|
-
t('common.confirm') // '确认' 或 'Confirm'(根据当前语言)
|
|
151
|
-
t('table.emptyText') // '暂无数据'
|
|
152
|
-
|
|
153
|
-
// 读取当前语言
|
|
154
|
-
console.log(locale.value.name) // 'zh-CN'
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
---
|
|
158
|
-
|
|
159
|
-
## 🛠 自定义语言包
|
|
160
|
-
|
|
161
|
-
如果内置语言包的翻译不满足需求,可以覆盖或扩展:
|
|
55
|
+
## Custom Locale
|
|
162
56
|
|
|
163
57
|
```ts
|
|
164
|
-
import
|
|
58
|
+
import zhCn from '@yh-ui/locale/lang/zh-cn'
|
|
165
59
|
import type { Language } from '@yh-ui/locale'
|
|
166
60
|
|
|
167
|
-
const
|
|
168
|
-
...
|
|
169
|
-
name: 'zh-
|
|
170
|
-
|
|
171
|
-
...
|
|
172
|
-
|
|
173
|
-
|
|
61
|
+
const customLocale: Language = {
|
|
62
|
+
...zhCn,
|
|
63
|
+
name: 'zh-cn-custom',
|
|
64
|
+
yh: {
|
|
65
|
+
...zhCn.yh,
|
|
66
|
+
common: {
|
|
67
|
+
...zhCn.yh?.common,
|
|
68
|
+
confirm: '好的',
|
|
69
|
+
cancel: '稍后'
|
|
70
|
+
}
|
|
174
71
|
}
|
|
175
72
|
}
|
|
176
|
-
|
|
177
|
-
app.use(YhUI, { locale: myLocale })
|
|
178
73
|
```
|
|
179
74
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
## ⚙️ TypeScript 类型
|
|
183
|
-
|
|
184
|
-
```ts
|
|
185
|
-
import type { Language, LocaleContext } from '@yh-ui/locale'
|
|
186
|
-
|
|
187
|
-
// Language: 完整的语言包类型
|
|
188
|
-
// LocaleContext: provide/inject 上下文类型
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
---
|
|
192
|
-
|
|
193
|
-
## ⚠️ 注意事项
|
|
194
|
-
|
|
195
|
-
- **RTL 语言**:阿拉伯语(`ar`)等 RTL 语言需配合 `YhConfigProvider` 的 `direction="rtl"` 属性使用
|
|
196
|
-
- **按需打包**:每个语言包独立文件,Vite/Webpack 会自动做 Tree-shaking,仅打包你导入的语言
|
|
197
|
-
- **SSR**:服务端渲染时语言包会正常加载,无 DOM 依赖,完全 SSR 安全
|
|
198
|
-
|
|
199
|
-
---
|
|
200
|
-
|
|
201
|
-
## 🔗 相关资源
|
|
75
|
+
## Language File Examples
|
|
202
76
|
|
|
203
|
-
-
|
|
204
|
-
- [📦 GitHub 仓库](https://github.com/1079161148/yh-ui)
|
|
77
|
+
`zh-cn`, `zh-tw`, `en`, `ja`, `ko`, `de`, `fr`, `es`, `pt`, `pt-br`, `ru`, `ar`, `tr`, `it`, `nl`, `pl`, `th`, `vi`, `id`, `ms`, `sv`, `fi`, `no`, `cs`, `sk`, `uk`, `hi`, `he`, `fa`, `el`, `ca`, `ta`, `bn`, `my`, `te` and more.
|
|
205
78
|
|
|
206
|
-
##
|
|
79
|
+
## License
|
|
207
80
|
|
|
208
|
-
MIT
|
|
81
|
+
MIT
|
package/dist/runtime.cjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "en", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _en.en;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "zhCn", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _zhCn.zhCn;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
var _zhCn = require("./lang/zh-cn.cjs");
|
|
19
|
+
var _en = require("./lang/en.cjs");
|
package/dist/runtime.mjs
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yh-ui/locale",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "YH-UI internationalization locale files",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"types": "./dist/lang/*.d.ts",
|
|
18
18
|
"import": "./dist/lang/*.mjs",
|
|
19
19
|
"require": "./dist/lang/*.cjs"
|
|
20
|
-
}
|
|
20
|
+
},
|
|
21
|
+
"./package.json": "./package.json"
|
|
21
22
|
},
|
|
22
23
|
"files": [
|
|
23
24
|
"dist"
|