@deot/docs-locale 1.0.1
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 +60 -0
- package/dist/index.cjs +879 -0
- package/dist/index.d.ts +886 -0
- package/dist/index.js +870 -0
- package/package.json +20 -0
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# @deot/docs-locale
|
|
2
|
+
|
|
3
|
+
`@deot/docs-locale` 为 Docs Client、Markdown、Playground 和 Renderer 提供统一的响应式界面翻译能力。内置 `zh-CN` 与 `en-US`,匹配失败或字段缺失时回退到 `en-US`。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @deot/docs-locale vue
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
`vue` 为 peer dependency(^3.5)。
|
|
12
|
+
|
|
13
|
+
## 使用
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import {
|
|
17
|
+
provideLocale,
|
|
18
|
+
resolveLocale,
|
|
19
|
+
useLocale
|
|
20
|
+
} from '@deot/docs-locale';
|
|
21
|
+
|
|
22
|
+
const locale = resolveLocale('zh-CN', {
|
|
23
|
+
'zh-CN': {
|
|
24
|
+
label: '简体中文',
|
|
25
|
+
client: {
|
|
26
|
+
search: { placeholder: '搜索文档' }
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
provideLocale(locale);
|
|
32
|
+
const { lang, t } = useLocale();
|
|
33
|
+
t('client.search.placeholder');
|
|
34
|
+
t('client.database.records', { count: 20 });
|
|
35
|
+
t('renderer.common.save');
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
每个 key 的第一段必须是实际渲染界面的包:`client.*`、`markdown.*`、`playground.*` 或 `renderer.*`。缺少插值参数时保留原占位符;English 中也不存在的 key 返回 key 本身。
|
|
39
|
+
|
|
40
|
+
`createLocale(name, partial)` 可创建以 English 补齐的独立语言对象;`resolveLocale(lang, locales)` 还会处理大小写、下划线以及 `zh` / `en` 别名。这些操作不会修改内置字典或用户配置。
|
|
41
|
+
|
|
42
|
+
## 公共导出
|
|
43
|
+
|
|
44
|
+
- 语言:`enUS`、`zhCN`。
|
|
45
|
+
- 构建:`createLocale`、`resolveLocale`、`buildTranslator`、`buildLocaleContext`。
|
|
46
|
+
- Vue:`provideLocale`、`useLocale`、`localeContextKey`。
|
|
47
|
+
- 类型:`Language`、`DocsLocaleEntry`、`DocsLocaleMessages`、`LocaleNamespace`、`LocaleKey`、`Translator` 等。
|
|
48
|
+
|
|
49
|
+
## 仓库内验证
|
|
50
|
+
|
|
51
|
+
在仓库根目录执行:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npm run test -- --package-name locale
|
|
55
|
+
npm run build -- --package-name locale
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## 许可证
|
|
59
|
+
|
|
60
|
+
MIT
|