@iquji-web/web-i18n 0.1.1 → 0.1.3
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/README.md +67 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,69 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @iquji-web/web-i18n
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
简体中文 | [English](README.en.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Iquji Web 轻量国际化方案,支持应用级词典注入、语言状态持久化、浏览器语言自动识别及模板参数插值。
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 安装
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @iquji-web/web-i18n
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## 核心特性与使用
|
|
18
|
+
|
|
19
|
+
### 1. 定义词典与注入 Provider
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { IqujiLocaleProvider, useIqujiLocale } from "@iquji-web/web-i18n";
|
|
23
|
+
|
|
24
|
+
const catalogs = {
|
|
25
|
+
"zh-CN": {
|
|
26
|
+
"app.title": "控制台",
|
|
27
|
+
"welcome.user": "欢迎回来,{name}!你有 {count} 条未读消息。",
|
|
28
|
+
},
|
|
29
|
+
"en-US": {
|
|
30
|
+
"app.title": "Dashboard",
|
|
31
|
+
"welcome.user": "Welcome back, {name}! You have {count} unread messages.",
|
|
32
|
+
},
|
|
33
|
+
} as const;
|
|
34
|
+
|
|
35
|
+
export function App() {
|
|
36
|
+
return (
|
|
37
|
+
<IqujiLocaleProvider catalogs={catalogs} defaultLocale="zh-CN" storageKey="app.locale">
|
|
38
|
+
<UserProfile />
|
|
39
|
+
</IqujiLocaleProvider>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function UserProfile() {
|
|
44
|
+
const { locale, setLocale, translate } = useIqujiLocale();
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<div>
|
|
48
|
+
<h1>{translate("app.title")}</h1>
|
|
49
|
+
<p>{translate("welcome.user", { name: "Alice", count: 3 })}</p>
|
|
50
|
+
|
|
51
|
+
<button onClick={() => setLocale(locale === "zh-CN" ? "en-US" : "zh-CN")}>
|
|
52
|
+
切换语言 (当前: {locale})
|
|
53
|
+
</button>
|
|
54
|
+
</div>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## 开发与构建
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
bun install --frozen-lockfile
|
|
65
|
+
bun run build # 编译打包到 dist/
|
|
66
|
+
bun run typecheck # 类型校验
|
|
67
|
+
bun run test # 单元测试
|
|
68
|
+
bun run check # 完整自检
|
|
69
|
+
```
|