File tree Expand file tree Collapse file tree 4 files changed +107
-5
lines changed Expand file tree Collapse file tree 4 files changed +107
-5
lines changed Original file line number Diff line number Diff line change 10
10
},
11
11
"dependencies" : {
12
12
"@lljj/vue-json-schema-form" : " 0.0.9" ,
13
+ "ajv-i18n" : " ^3.5.0" ,
13
14
"vue" : " ^2.6.10"
14
15
},
15
16
"devDependencies" : {
Original file line number Diff line number Diff line change @@ -16,13 +16,14 @@ yarn add @lljj/vue-json-schema-form
16
16
<script src =" //cdn.jsdelivr.net/npm/@lljj/vue-json-schema-form/dist/vueJsonSchemaForm.umd.min.js" ></script >
17
17
```
18
18
19
- ::: tip
20
- * 如果存在Vue 全局变量,会注册全局组件 ` VueForm `
19
+ ::: tip 全局引入
20
+ * 全局引入,会注册全局组件 ` VueForm `
21
+ * 暴露全局变量 ` window.vueJsonSchemaForm `
21
22
:::
22
23
23
24
## 展现形式
24
- 通过schema生对应的form表单
25
- * schema ` title ` 属性作为formItem 标题
25
+ 通过 schema 生对应的form表单
26
+ * schema ` title ` 属性作为 form表单的标题
26
27
* schema ` description ` 属性作为表单的描述
27
28
28
29
具体效果参见下面demo,点击显示代码可查看源代码或者在codepen运行
Original file line number Diff line number Diff line change 1
1
# 多语言支持
2
2
3
3
## 默认中文
4
+ 默认语言为中文,包含 表单内容多语言 和 ajv校验信息 两部分。
4
5
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
+ ```
5
101
6
- ## 配置多语言,底层校验错误使用 ajv i18n
Original file line number Diff line number Diff line change @@ -2824,6 +2824,11 @@ ajv-errors@^1.0.0:
2824
2824
resolved "https://registry.yarnpkg.com/ajv-errors/-/ajv-errors-1.0.1.tgz#f35986aceb91afadec4102fbd85014950cefa64d"
2825
2825
integrity sha512-DCRfO/4nQ+89p/RK43i8Ezd41EqdGIU4ld7nGF8OQ14oc/we5rEntLCUa7+jrn3nn83BosfwZA0wb4pon2o8iQ==
2826
2826
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
+
2827
2832
ajv-keywords@^3.1.0, ajv-keywords@^3.4.1:
2828
2833
version "3.4.1"
2829
2834
resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-3.4.1.tgz#ef916e271c64ac12171fd8384eaae6b2345854da"
You can’t perform that action at this time.
0 commit comments