Difference between revisions of "LRM XML Support"
(→Limitations of XML Definition) |
(→TOKEN_TRANSLATABLE cannot be an attribute of an non-key, non-value element) |
||
Line 131: | Line 131: | ||
==== TOKEN_TRANSLATABLE cannot be an attribute of an non-key, non-value element ==== |
==== TOKEN_TRANSLATABLE cannot be an attribute of an non-key, non-value element ==== |
||
+ | A xml file that has the isTranslatable flag set in its own element is not supported by LRM |
||
<?xml version='1.0' encoding='utf-8'?> |
<?xml version='1.0' encoding='utf-8'?> |
||
<<nowiki/>root> |
<<nowiki/>root> |
||
Line 136: | Line 137: | ||
<<nowiki/>string name="TOKEN_KEY">TOKEN_VALUE<<nowiki/>/string> |
<<nowiki/>string name="TOKEN_KEY">TOKEN_VALUE<<nowiki/>/string> |
||
<<nowiki/>info istrans="TOKEN_TRANSLATABLE"><<nowiki/>/info> |
<<nowiki/>info istrans="TOKEN_TRANSLATABLE"><<nowiki/>/info> |
||
+ | <<nowiki/>/data> |
||
+ | <<nowiki/>/root> |
||
+ | |||
+ | ==== Number of elements cannot exceed 4 ==== |
||
+ | The only content in the xmlParser.xml is information leading to location of key/values. No other information is necessary. |
||
+ | <?xml version='1.0' encoding='utf-8'?> |
||
+ | <<nowiki/>root> |
||
+ | <<nowiki/>data> |
||
+ | <<nowiki/>key>TOKEN_KEY</key> |
||
+ | <<nowiki/string>TOKEN_VALUE<<nowiki/>/string> |
||
+ | <<nowiki/addtlInfo></addtInfo> |
||
<<nowiki/>/data> |
<<nowiki/>/data> |
||
<<nowiki/>/root> |
<<nowiki/>/root> |
Revision as of 19:39, 1 September 2017
Contents
Formatting xml files
LRM uses the xmlParser.xml file to parse any extensions that have a xml parser type. This file is located in the ../L10nStreamlining/<group>/projects/<project>/config folder.
XML Parser Syntax
The xmlParser.xml directs LRM on the location of the keys and values within the xml files as well as whether the key/value is translatable. The xml syntax is defined by 3 tokens:
- TOKEN_KEY is required and can be defined as either an attribute or a text node. For example:
- <data>TOKEN_KEY</data>
- <entry name="TOKEN_KEY"></entry>
- TOKEN_TRANSLATABLE is optional and can only be defined as an attribute. For example:
- <key name="TOKEN_KEY" istrans="TOKEN_TRANSLATABLE"></key>
- TOKEN_VALUE is required and can only be defined as a text node. For example:
- <value>TOKEN_VALUE</value>
Limitations of XML Definition
There are structural limitations to xml files that can be parsed by LRM.
- TOKEN_KEY must be defined before TOKEN_VALUE
- Tokens can only be defined once
- The TOKEN_KEY can have, at most, 1 parent
- TOKEN_TRANSLATABLE must be an attribute of either the TOKEN_KEY element or the TOKEN_VALUE element
- At most, 4 elements will be defined; root element, parent of key element, key element and value element.
OTB XML Parser Definitions
There are 3 out-of-the-box parser definitions for XML files.
- AndroidParser.xml format definition used for as the default for .xml extensions.
- ResxParser.xml format definition used for .resx extensions.
- RxmlParser.xml format definition used for .rxml extensions.
Unique XML Parser Definitions
There are several layout combinations that can be used to define your unique xml file.
- element of the key attribute is the parent of the value element such as .resx files
- value is the text node of the element of the key attribute such as Android files
AndroidParser.xml structure
The AndroidParser.xml file defines the structure of Android files.
Sample Android xml file
A typical Android file has the following structure:
<?xml version="1.0" encoding="UTF-8"?> <resources> <string name=""hello_world"" translatable=""true"">Hello World</string> <string name=""goodbye"" translatable=""true"">Good Bye</string> </resources>
Parser definition for Android files
For Android files, the value is the text node of the element of the key attribute:
<?xml version='1.0' encoding='utf-8'?> <resources> <string name="TOKEN_KEY" translatable="TOKEN_TRANSLATABLE">TOKEN_VALUE</string> </resources>
ResxParser.xml structure
The ResxParser.xml file defines the structure of .resx xml files.
Sample Resx xml file
A typical Resx file has the following structure:
<?xml version="1.0" encoding="UTF-8"?> <root> <data name="hello_world"> <value>Hello World</value> <data name="goodbye"> <value>Good Bye</value> </root>
Parser definition for Resx files
For Resx files, the element of the key attribute is the parent of the value element:
<?xml version='1.0' encoding='utf-8'?> <root> <data name="TOKEN_KEY" > <value>TOKEN_VALUE</value> </root>
RxmlParser.xml structure
The RxmlParser.xml file defines the structure of .rxml xml files.
Sample Rxml xml file
A typical Rxml file has the following structure:
<?xml version="1.0" encoding="UTF-8"?> <properties> <entry key="hello_world">Hello World</entry> <entry key="goodbye">Good Bye</entry> </properties>
Parser definition for Rxml files
<?xml version="1.0" encoding="UTF-8"?> <properties> <entry key="TOKEN_KEY">TOKEN_VALUE</entry> </properties>
Invalid xmlParser.xml Examples
TOKEN_VALUE cannot be defined before TOKEN_KEY
<?xml version='1.0' encoding='utf-8'?> <data> <value>TOKEN_VALUE</value> <entry>TOKEN_KEY</entry> </data>
Tokens cannot appear more than once in the xmlParser.xml file
<?xml version='1.0' encoding='utf-8'?> <root> <string name="TOKEN_KEY">TOKEN_VALUE</string> <value>TOKEN_VALUE</value> </root>
TOKEN_KEY cannot have more than 1 parent
<?xml version='1.0' encoding='utf-8'?> <root> <parent1> <parent2> <string name="TOKEN_KEY">TOKEN_VALUE</string> </parent2> </parent1> </root>
TOKEN_TRANSLATABLE cannot be an attribute of an non-key, non-value element
A xml file that has the isTranslatable flag set in its own element is not supported by LRM
<?xml version='1.0' encoding='utf-8'?> <root> <data> <string name="TOKEN_KEY">TOKEN_VALUE</string> <info istrans="TOKEN_TRANSLATABLE"></info> </data> </root>
Number of elements cannot exceed 4
The only content in the xmlParser.xml is information leading to location of key/values. No other information is necessary.
<?xml version='1.0' encoding='utf-8'?> <root> <data> <key>TOKEN_KEY</key> <<nowiki/string>TOKEN_VALUE</string> <<nowiki/addtlInfo></addtInfo> </data> </root>