Skip to content

Commit 211f276

Browse files
committed
docs(docs): 添加文档,i18n
1 parent aa49af4 commit 211f276

File tree

4 files changed

+107
-5
lines changed

4 files changed

+107
-5
lines changed

packages/demo/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
},
1111
"dependencies": {
1212
"@lljj/vue-json-schema-form": "0.0.9",
13+
"ajv-i18n": "^3.5.0",
1314
"vue": "^2.6.10"
1415
},
1516
"devDependencies": {

packages/docs/docs/zh/guide/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ yarn add @lljj/vue-json-schema-form
1616
<script src="//cdn.jsdelivr.net/npm/@lljj/vue-json-schema-form/dist/vueJsonSchemaForm.umd.min.js"></script>
1717
```
1818

19-
::: tip
20-
* 如果存在Vue 全局变量,会注册全局组件 `VueForm`
19+
::: tip 全局引入
20+
* 全局引入,会注册全局组件 `VueForm`
21+
* 暴露全局变量 `window.vueJsonSchemaForm`
2122
:::
2223

2324
## 展现形式
24-
通过schema生对应的form表单
25-
* schema `title` 属性作为formItem 标题
25+
通过 schema 生对应的form表单
26+
* schema `title` 属性作为 form表单的标题
2627
* schema `description` 属性作为表单的描述
2728

2829
具体效果参见下面demo,点击显示代码可查看源代码或者在codepen运行

packages/docs/docs/zh/guide/i18n.md

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,101 @@
11
# 多语言支持
22

33
## 默认中文
4+
默认语言为中文,包含 表单内容多语言 和 ajv校验信息 两部分。
45

6+
## 配置多语言
7+
8+
### 表单内容多语言
9+
10+
* 配置默认`formFooter` 确认和取消按钮
11+
12+
```js
13+
formFooter = {
14+
okBtn: 'Save', // 确认按钮文字
15+
cancelBtn: 'Cancel' // 取消按钮文字
16+
}
17+
```
18+
19+
* 配置表单渲染多语言文案
20+
21+
直接通过对应的 schema 配置即可,另外需要借助你项目本身提供的翻译方法实现。
22+
23+
::: tip
24+
这里推荐所有需要多语言的文案都通过 `uiSchema` 配置
25+
26+
这样可以保证 `schema` 为标准的json schema语法,方便需要后端统一校验的时候快速转换给后端使用。
27+
:::
28+
29+
如:
30+
31+
::: demo
32+
```html
33+
<template>
34+
<vue-form
35+
v-model="formData"
36+
:schema="schema"
37+
:form-footer="formFooter"
38+
:ui-schema="uiSchema"
39+
>
40+
</vue-form>
41+
</template>
42+
<script>
43+
// 模拟语言包
44+
const transKeyMap = {
45+
userName: 'Username'
46+
};
47+
48+
// 模拟翻译方法
49+
const trans = key => transKeyMap[key] || `transKeyMap.${key}`;
50+
51+
export default {
52+
name: 'Demo',
53+
data() {
54+
return {
55+
formData: {},
56+
schema: {
57+
type: 'object',
58+
required: [
59+
'userName'
60+
],
61+
properties: {
62+
userName: {
63+
type: 'string',
64+
title: '用户名'
65+
}
66+
}
67+
},
68+
formFooter: {
69+
okBtn: 'Save', // 确认按钮文字
70+
cancelBtn: 'Cancel' // 取消按钮文字
71+
},
72+
uiSchema: {
73+
userName: {
74+
'ui:options': {
75+
title: trans('userName')
76+
},
77+
}
78+
},
79+
};
80+
}
81+
};
82+
</script>
83+
```
84+
:::
85+
86+
### 校验信息多语言
87+
schema校验使用 `ajv``i18n` 直接使用 [ajv i18n](https://github.com/ajv-validator/ajv-i18n)
88+
89+
```ssh
90+
npm install ajv-i18n
91+
```
92+
93+
项目中导入你需要的语言:
94+
```js
95+
import localizeEn from 'ajv-i18n/localize/en';
96+
import { i18n } from '@lljj/vue-json-schema-form';
97+
98+
// 设置使用语言
99+
i18n.useLocal(localizeEn);
100+
```
5101

6-
## 配置多语言,底层校验错误使用 ajv i18n

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2824,6 +2824,11 @@ ajv-errors@^1.0.0:
28242824
resolved "https://registry.yarnpkg.com/ajv-errors/-/ajv-errors-1.0.1.tgz#f35986aceb91afadec4102fbd85014950cefa64d"
28252825
integrity sha512-DCRfO/4nQ+89p/RK43i8Ezd41EqdGIU4ld7nGF8OQ14oc/we5rEntLCUa7+jrn3nn83BosfwZA0wb4pon2o8iQ==
28262826

2827+
ajv-i18n@^3.5.0:
2828+
version "3.5.0"
2829+
resolved "https://registry.yarnpkg.com/ajv-i18n/-/ajv-i18n-3.5.0.tgz#63235ebc8779ac50cfa320aa123d93a0d6911b00"
2830+
integrity sha512-IR8uhRH0La4DweKHqBOVeoNo2prJ3bowWzGtNS3uDvYv5wKLgH/WQsoh6gHPVxTWXCGr+R+6I5vXDSXGAYnNPA==
2831+
28272832
ajv-keywords@^3.1.0, ajv-keywords@^3.4.1:
28282833
version "3.4.1"
28292834
resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-3.4.1.tgz#ef916e271c64ac12171fd8384eaae6b2345854da"

0 commit comments

Comments
 (0)