Skip to content

Commit b37a6bc

Browse files
committedApr 28, 2023
Add XML validation scripts
The basic structure of the regular translation file has been codified as schema/translation.xsd while the structure of the one-per-locale properties.xml is codified in schema/properties.xsd. A validation shell script has been included as ./validate.sh that checks that all the XML files are valid and match the corresponding schema. More checks can be added later such as making keys corresponding to known integral values also have (sane?) integral values.
1 parent 13b11a9 commit b37a6bc

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed
 

‎schema/properties.xsd

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
2+
<xs:element name="localization">
3+
<xs:complexType>
4+
<xs:sequence>
5+
<xs:element name="locale">
6+
<xs:complexType>
7+
<xs:sequence>
8+
<xs:element name="name" type="xs:string"/>
9+
<xs:element name="rtl" type="xs:boolean"/>
10+
<xs:element name="parentLocale" type="xs:string"/>
11+
</xs:sequence>
12+
</xs:complexType>
13+
</xs:element>
14+
</xs:sequence>
15+
</xs:complexType>
16+
</xs:element>
17+
</xs:schema>

‎schema/translation.xsd

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
2+
<xs:attributeGroup name="entryGroup">
3+
<xs:attribute name="key" type="xs:string"/>
4+
<xs:attribute name="value" type="xs:string"/>
5+
<xs:attribute name="version" type="xs:byte"/>
6+
<xs:attribute name="clone" type="xs:string"/>
7+
<xs:attribute name="derive" type="xs:boolean"/>
8+
</xs:attributeGroup>
9+
<xs:element name="localization">
10+
<xs:complexType>
11+
<xs:sequence>
12+
<xs:element name="strings">
13+
<xs:complexType>
14+
<xs:sequence>
15+
<xs:element name="string" maxOccurs="unbounded" minOccurs="1">
16+
<xs:complexType>
17+
<xs:simpleContent>
18+
<xs:extension base="xs:string">
19+
<xs:attributeGroup ref="entryGroup"/>
20+
</xs:extension>
21+
</xs:simpleContent>
22+
</xs:complexType>
23+
</xs:element>
24+
</xs:sequence>
25+
</xs:complexType>
26+
</xs:element>
27+
</xs:sequence>
28+
</xs:complexType>
29+
</xs:element>
30+
</xs:schema>

‎validate.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
3+
xmlvalidate() {
4+
schema=$1
5+
file=$2
6+
7+
result=$(xmllint --schema $schema --encode utf-8 --noout "$file" 2>&1)
8+
status=$?
9+
if test $status -ne 0; then
10+
echo $result 1>&2
11+
fi
12+
}
13+
14+
for file in $(find . -iname "*.xml" ! -iname "properties.xml"); do
15+
xmlvalidate ./schema/translation.xsd $file
16+
done
17+
18+
for file in $(find -iname "properties.xml"); do
19+
xmlvalidate ./schema/properties.xsd $file
20+
done

0 commit comments

Comments
 (0)
Please sign in to comment.