Skip to content

Commit b1b6862

Browse files
committed
i18n support via new keywords "defaultLocale", "locales", and "localeKey"
1 parent c75c528 commit b1b6862

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

jsonschema-schema.xml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<!ENTITY RFC3986 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3986.xml">
99
<!ENTITY RFC4627 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.4627.xml">
1010
<!ENTITY RFC5322 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.5322.xml">
11+
<!ENTITY RFC5646 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.5646.xml">
1112
]>
1213
<?rfc toc="yes"?>
1314
<?rfc symrefs="yes"?>
@@ -997,6 +998,54 @@
997998

998999
</section>
9991000

1001+
<section title='"defaultLocale", "locales", and "localeKey"'>
1002+
1003+
<section title="Valid values">
1004+
<t>
1005+
The value of "defaultLocale" MUST be a valid <xref target="RFC5646">RFC 5646</xref>
1006+
language tag or it will default to "en". Its value (including the case
1007+
where the default "en" is assumed) MAY also be present as a property on the
1008+
"locales" object or otherwise, it will be assumed to be indicating the language
1009+
used on keywords such as "title" directly present on a schema object.
1010+
"localeKey" MUST be a string and MUST also be present as a property on the
1011+
language tag subobject indicated by "defaultLocale" on the "locales" object.
1012+
"locales" MUST be an object whose property names are valid
1013+
<xref target="RFC5646">RFC 5646</xref> language tags and whose value is an
1014+
object, and these language tag subobjects MUST have properties whose names are
1015+
any string and whose value is an object which MAY contain any of the
1016+
following properties: "title", "description", "default", "pattern", and "enum",
1017+
whose values must be valid values for the JSON Schema keywords of the same
1018+
name.
1019+
</t>
1020+
</section>
1021+
1022+
<section title="Purpose">
1023+
<t>
1024+
These keywords are used for internationalization (i18n). When "localeKey"
1025+
is present on a schema, a locale lookup SHOULD be made by the application
1026+
unless the "defaultLocale" value matches the application-determined user locale,
1027+
in which case, the normal treatment of keywords such as "title" MUST occur.
1028+
If a locale lookup is made, the application-determined user locale MUST match
1029+
a property of "locales", and one of these subobject properties SHOULD
1030+
be matched by the value of "localeKey". Upon finding a match, the application
1031+
MUST override the normal behavior of the following keywords (whether already
1032+
present as keywords or not) with the corresponding properties on the
1033+
"localeKey"-matched object: "title", "description", "default", "pattern",
1034+
and "enum". If no match is found, the "defaultLocale" MUST be used to
1035+
find a match from a locale lookup, similarly overriding behaviors upon any
1036+
match while reporting a failure to the application if no match is found.
1037+
When "localeKey" is not present, the keywords, if present, will retain
1038+
their normal behaviors.
1039+
</t>
1040+
1041+
<t>
1042+
"defaultLocale" and "locales" MAY be used in root schemas while "localeKey"
1043+
MAY be used on root schemas and in any subschemas.
1044+
</t>
1045+
</section>
1046+
1047+
</section>
1048+
10001049
<section title='"default"'>
10011050

10021051
<section title="Valid values">
@@ -1325,6 +1374,7 @@
13251374
&RFC3986;
13261375
&RFC4627;
13271376
&RFC5322;
1377+
&RFC5646;
13281378
<reference anchor="ecma262"
13291379
target="http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf">
13301380
<front>

schema.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,32 @@
4141
"description": {
4242
"type": "string"
4343
},
44+
"defaultLocale": {
45+
"type": "string"
46+
},
47+
"locales": {
48+
"type": "object",
49+
"patternProperties": {
50+
".{2,}": {
51+
"type": "object",
52+
"patternProperties": {
53+
".*": {
54+
"type": "object",
55+
"properties": {
56+
"title": { "$ref": "#/properties/title" },
57+
"description": { "$ref": "#/properties/description" }
58+
"default": { "$ref": "#/properties/default" }
59+
"pattern": { "$ref": "#/properties/pattern" }
60+
"enum": { "$ref": "#/properties/enum" }
61+
}
62+
}
63+
}
64+
}
65+
}
66+
},
67+
"localeKey": {
68+
"type": "string"
69+
},
4470
"default": {},
4571
"multipleOf": {
4672
"type": "number",

0 commit comments

Comments
 (0)