Difference between revisions of "LRM resx Support"

From Lingoport Wiki
Jump to: navigation, search
(Created page with "The .Net framework provides for a LRM supports .resx files. See https://msdn.microsoft.com/en-us/library/ekyft91f(v=vs.100).aspx . == Example of Supported .resx Files == * T...")
 
(xml parser type using ResxParser.xml format definition)
 
(18 intermediate revisions by 3 users not shown)
Line 1: Line 1:
The .Net framework provides for a LRM supports .resx files.
+
The .resx resource file format consists of XML entries, which specify objects and strings inside XML tags. LRM supports .resx files.
 
See https://msdn.microsoft.com/en-us/library/ekyft91f(v=vs.100).aspx .
 
See https://msdn.microsoft.com/en-us/library/ekyft91f(v=vs.100).aspx .
  +
== Locale File Extensions ==
== Example of Supported .resx Files ==
 
* The resx files follow this naming convention: '''filename.<language>.resx''' or '''filename.<language>-<country>.resx'''. For example, '''resources.json''' or resources.en.json for a base file, '''resources.fr.json''' or resources.fr-FR.json, etc.
+
* The resx files follow this naming convention: '''filename.<language>.resx''' or '''filename.<language>-<country>.resx'''. For example, '''resources.resx''' or resources.en.resx for a base file, '''resources.fr.resx''' or resources.fr-FR.resx, etc.
 
* '''If you can, avoid duplicate file names'''. Duplications incur more prep kits than necessary.
 
* '''If you can, avoid duplicate file names'''. Duplications incur more prep kits than necessary.
   
=== Simple is Best ===
+
== What is resx files encoding?==
  +
.Net resx files must be UTF-8 encoded, as per the resx schema, Hence, on-boarding resx resource files with LRM must specify the UTF-8 encoding:
A file with <b>one key value per line</b>, with some possible semantics in the key, is the preferred way to have .json resource bundles. There is no structure (no objects) to the file, so changing keys, moving them around, does not affect whatever outstanding translation will be returned at a later date with a different structure.
 
<b>resources_en.json</b>
 
{
 
"site_heading": "Where can I find more information on the site?",
 
"site_subHeading2": "Search",
 
"enableGeo": "Enable location services in your browser to load local help results.",
 
"findButton": "Find",
 
"gettingStarted_title": "Getting Started",
 
"gettingStarted_subHeading": "Here are the main things you need to know as you
 
get started.",
 
"logging_off_account": "Log off"
 
}
 
   
  +
<pre>
=== If you want complexity ===
 
  +
<?xml version="1.0" encoding="utf-8"?>
  +
<root>
  +
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  +
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
  +
<xsd:element name="data">
  +
<xsd:complexType>
  +
<xsd:sequence>
  +
<xsd:element name="value" type="xsd:string" minOccurs="0"
  +
msdata:Ordinal="2" />
  +
</xsd:sequence>
  +
<xsd:attribute name="name" type="xsd:string" />
  +
<xsd:attribute name="type" type="xsd:string" />
  +
<xsd:attribute name="mimetype" type="xsd:string" />
  +
</xsd:complexType>
  +
</xsd:element>
   
  +
</pre>
<b>Caveat</b>
 
JSON structure changes can lead to problems with project on-boarded for file deltas (v. Full Files).
 
   
  +
== Example of .resx Files or a file extension that uses the ''xml'' parser type and the ResxParser.xml definition ==
== In what format should JSON Files be for LRM Handling ?==
 
  +
<pre>
  +
<?xml version="1.0" encoding="UTF-8"?>
  +
<root>
  +
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
  +
<xsd:element msdata:IsDataSet="true" name="root">
  +
<xsd:complexType>
  +
<xsd:choice maxOccurs="unbounded">
  +
<xsd:element name="data">
  +
<xsd:complexType>
  +
<xsd:sequence>
  +
<xsd:element minOccurs="0" msdata:Ordinal="1" name="value" type="xsd:string" />
  +
<xsd:element minOccurs="0" msdata:Ordinal="2" name="comment" type="xsd:string" />
  +
</xsd:sequence>
  +
<xsd:attribute msdata:Ordinal="1" name="name" type="xsd:string" />
  +
<xsd:attribute msdata:Ordinal="3" name="type" type="xsd:string" />
  +
<xsd:attribute msdata:Ordinal="4" name="mimetype" type="xsd:string" />
  +
</xsd:complexType>
  +
</xsd:element>
  +
<xsd:element name="resheader">
  +
<xsd:complexType>
  +
<xsd:sequence>
  +
<xsd:element minOccurs="0" msdata:Ordinal="1" name="value" type="xsd:string" />
  +
</xsd:sequence>
  +
<xsd:attribute name="name" type="xsd:string" use="required" />
  +
</xsd:complexType>
  +
</xsd:element>
  +
</xsd:choice>
  +
</xsd:complexType>
  +
</xsd:element>
  +
</xsd:schema>
  +
<resheader name="resmimetype">
  +
<value>text/microsoft-resx</value>
  +
</resheader>
  +
<resheader name="version">
  +
<value>1.3</value>
  +
</resheader>
  +
<resheader name="reader">
  +
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
  +
</resheader>
  +
<resheader name="writer">
  +
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
  +
</resheader>
  +
<data name="CARO_CAROPTI_100" xml:space="preserve"><value>Car Option</value></data>
  +
<data name="COMM_THISSHO_1" xml:space="preserve"><value>this should be detected</value></data>
  +
</root>
  +
</pre>
   
  +
== ''xml'' parser type using ResxParser.xml format definition ==
===Arrays are not allowed in the context of JSON files as resource bundles===
 
  +
=== valid resx syntax ===
String references in the code, from an i18n point of view, is unmanageable for JSON arrays. In addition, many L10n vendors do not support JSON arrays. (Sample JSON files are located in LRM-Server-2.1/''samples/JSON_Examples''):
 
  +
Files that use the ''xml'' parser and the [[LRM_XML_Support#ResxParser.xml_structure|ResxParser.xml]] format definition are expected to have valid resx syntax
===There is only one key/value per line===
 
*Valid
 
"key1":"This is my value for key1",
 
"key2":"This is my value for key2"
 
*Invalid
 
"key1":"This is my value for key1","key2":"This is my value for key2"
 
===End-object character (curly bracket) may not exist on the same line as a key/value===
 
* Valid
 
"keys": {
 
"key1":"This is my value for key1"
 
}
 
* Invalid
 
<code>"keys": {
 
"key1":"This is my value for key1"</code>'''}'''
 
===Values associated with a key must be a string===
 
Numeric and boolean values are not allowed
 
* Valid
 
"key1":"0"
 
* Invalid
 
"key1":0
 
"key1": true
 
   
  +
=== .resx uses the ''xml'' parser type===
== Sample LRM Project Definition File for .json ==
 
  +
When defining a project containing LRM Standard .resx resource files, there is no need to define a ''&lt;parser-type&gt;'' as the ''xml'' parser will always be used along with the ResxParser.xml format definition.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
 
  +
<lrmconf>
 
  +
=== unique file extension needs to define ''xml'' parser type and copy over the ResxParser.xml format definition ===
<model-version>3.0.18</model-version>
 
  +
If a unique file extension is a valid resx file, then:
<project-name>search</project-name>
 
  +
<ul>
<project-desc>Search project</project-desc>
 
  +
<li>In the Project definition xml file, ''&lt;parser-type&gt;'' should be ''xml'' </li>
  +
<li>After creating the project
  +
<ul>
  +
<li>Copy over the ResxParser.xml format definition located in ../lrm-server-&lt;x.x&gt;/samples/XmlParserExamples into the ../L10nStreamlining/&lt;group&gt;/projects/&lt;project&gt;/config folder</li>
  +
<li>Rename file ResxParser.xml to xmlParser.xml</li>
  +
</ul>
  +
</ul>
  +
  +
== Sample LRM Project Definition File for .resx==
  +
<?xml version="1.0" encoding="UTF-8"?>
  +
<lrmconf>
  +
<model-version>1.0.0</model-version>
  +
<project-name>WinApp</project-name>
  +
<project-desc>Lingoport.WinApp is configured to support resx resource files</project-desc>
 
<group-name>Lingoport</group-name>
 
<group-name>Lingoport</group-name>
<top-level-dir>/var/lib/jenkins/jobs/Lingoport.search/workspace</top-level-dir>
+
<top-level-dir>/var/lib/jenkins/jobs/Lingoport.WinApp/workspace</top-level-dir>
 
<detect-errors>
 
<detect-errors>
 
<missed-trans-error>0</missed-trans-error>
 
<missed-trans-error>0</missed-trans-error>
 
<parameter-mismatch-error>1</parameter-mismatch-error>
 
<parameter-mismatch-error>1</parameter-mismatch-error>
  +
</detect-errors>
 
<track-back-locale>br</track-back-locale>
 
<track-back-locale>br</track-back-locale>
  +
<pseudo-locale>eo</pseudo-locale>
 
<target-locales>
 
<target-locales>
<locale>es</locale>
+
<locale>de</locale>
 
<locale>fr</locale>
 
<locale>fr</locale>
 
<locale>ja</locale>
 
<locale>ja</locale>
 
</target-locales>
 
</target-locales>
<default-locale>en</default-locale>
+
<default-locale>en_US</default-locale>
 
<resource-extensions>
 
<resource-extensions>
  +
<resource-extension>
  +
'''&lt;!-- parser-type not needed since .resx is a standard LRM extension that maps to the xml parser type --&gt;'''
  +
'''<extension>resx</extension>'''
  +
'''<file-name-pattern>*.l-c-v</file-name-pattern>'''
  +
'''<use-pattern-on-dflt-locale>0</use-pattern-on-dflt-locale>'''
  +
'''<file-location-pattern></file-location-pattern>'''
  +
'''<use-location-pattern-on-dflt-locale>0</use-location-pattern-on-dflt-locale>'''
  +
'''<base-file-encoding>UTF-8</base-file-encoding>'''
  +
'''<localized-file-encoding>UTF-8</localized-file-encoding>'''
  +
'''<parameter-regex-pattern><![CDATA[%[ds]|%\d+\$[ds]|%\{\w+\}]]></parameter-regex-pattern>'''
  +
</resource-extension>
 
<resource-extension>
 
<resource-extension>
  +
'''&lt;!-- parser-type is required because .myext is not a standard LRM extension --&gt;'''
'''<extension>json</extension>'''
 
'''<file-name-pattern>*_l-c-v</file-name-pattern>'''
+
'''<extension>''myext''</extension>'''
  +
'''''&lt;!-- Once the project is created, the ResxParser.xml, located in the samples/XmlParserExamples, '''''
'''<use-pattern-on-dflt-locale>1</use-pattern-on-dflt-locale>'''
 
  +
''''' needs to copied over the project's config folder and renamed xmlParser.xml --&gt;'''''
'''<file-location-pattern/>'''
 
  +
'''''<parser-type>xml</parser-type>'''''
  +
'''<file-name-pattern>*.l-c-v</file-name-pattern>'''
  +
'''<use-pattern-on-dflt-locale>0</use-pattern-on-dflt-locale>'''
  +
'''<file-location-pattern></file-location-pattern>'''
 
'''<use-location-pattern-on-dflt-locale>0</use-location-pattern-on-dflt-locale>'''
 
'''<use-location-pattern-on-dflt-locale>0</use-location-pattern-on-dflt-locale>'''
 
'''<base-file-encoding>UTF-8</base-file-encoding>'''
 
'''<base-file-encoding>UTF-8</base-file-encoding>'''
 
'''<localized-file-encoding>UTF-8</localized-file-encoding>'''
 
'''<localized-file-encoding>UTF-8</localized-file-encoding>'''
'''<parameter-regex-pattern><![CDATA[\{\w+\}|%[ds]]]></parameter-regex-pattern>'''
+
'''<parameter-regex-pattern><![CDATA[%[ds]|%\d+\$[ds]|%\{\w+\}]]></parameter-regex-pattern>'''
 
</resource-extension>
 
</resource-extension>
 
</resource-extensions>
 
</resource-extensions>
 
<dirset>
 
<dirset>
 
<includes>
 
<includes>
<include-dir>**/**</include-dir>
+
<include-dir-file>**/**</include-dir-file>
 
</includes>
 
</includes>
<excludes>
+
<excludes>
<exclude-dir-file/>
+
<exclude-dir-file>**/source/bin/**</exclude-dir-file>
<exclude-dir-file>**/*_eo.json</exclude-dir-file>
 
<exclude-dir-file>**/*_eo__*.json</exclude-dir-file>
 
<exclude-dir-file>**/*_br.json</exclude-dir-file>
 
<exclude-dir-file>**/LRMScans/**</exclude-dir-file>
 
<exclude-dir-file>**/GlobalyzerScans/**</exclude-dir-file>
 
<exclude-dir-file>**/sonar-project.properties</exclude-dir-file>
 
 
</excludes>
 
</excludes>
 
</dirset>
 
</dirset>

Latest revision as of 19:05, 1 September 2017

The .resx resource file format consists of XML entries, which specify objects and strings inside XML tags. LRM supports .resx files. See https://msdn.microsoft.com/en-us/library/ekyft91f(v=vs.100).aspx .

Locale File Extensions

  • The resx files follow this naming convention: filename.<language>.resx or filename.<language>-<country>.resx. For example, resources.resx or resources.en.resx for a base file, resources.fr.resx or resources.fr-FR.resx, etc.
  • If you can, avoid duplicate file names. Duplications incur more prep kits than necessary.

What is resx files encoding?

.Net resx files must be UTF-8 encoded, as per the resx schema, Hence, on-boarding resx resource files with LRM must specify the UTF-8 encoding:

<?xml version="1.0" encoding="utf-8"?>
<root>
    <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="data">
     <xsd:complexType>
           <xsd:sequence>
                <xsd:element name="value" type="xsd:string" minOccurs="0"
                    msdata:Ordinal="2" />
            </xsd:sequence>
                <xsd:attribute name="name" type="xsd:string" />
                <xsd:attribute name="type" type="xsd:string" />
                <xsd:attribute name="mimetype" type="xsd:string" />
      </xsd:complexType>
</xsd:element>

Example of .resx Files or a file extension that uses the xml parser type and the ResxParser.xml definition

  <?xml version="1.0" encoding="UTF-8"?>
  <root>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
        <xsd:element msdata:IsDataSet="true" name="root">
            <xsd:complexType>
                <xsd:choice maxOccurs="unbounded">
                    <xsd:element name="data">
                        <xsd:complexType>
                            <xsd:sequence>
                                <xsd:element minOccurs="0" msdata:Ordinal="1" name="value" type="xsd:string" />
                                <xsd:element minOccurs="0" msdata:Ordinal="2" name="comment" type="xsd:string" />
                            </xsd:sequence>
                            <xsd:attribute msdata:Ordinal="1" name="name" type="xsd:string" />
                            <xsd:attribute msdata:Ordinal="3" name="type" type="xsd:string" />
                            <xsd:attribute msdata:Ordinal="4" name="mimetype" type="xsd:string" />
                        </xsd:complexType>
                    </xsd:element>
                    <xsd:element name="resheader">
                        <xsd:complexType>
                            <xsd:sequence>
                                <xsd:element minOccurs="0" msdata:Ordinal="1" name="value" type="xsd:string" />
                            </xsd:sequence>
                            <xsd:attribute name="name" type="xsd:string" use="required" />
                        </xsd:complexType>
                    </xsd:element>
                </xsd:choice>
            </xsd:complexType>
        </xsd:element>
    </xsd:schema>
    <resheader name="resmimetype">
        <value>text/microsoft-resx</value>
    </resheader>
    <resheader name="version">
        <value>1.3</value>
    </resheader>
    <resheader name="reader">
        <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
    </resheader>
    <resheader name="writer">
        <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
    </resheader>
    <data name="CARO_CAROPTI_100" xml:space="preserve"><value>Car Option</value></data>
    <data name="COMM_THISSHO_1" xml:space="preserve"><value>this should be detected</value></data>
  </root>

xml parser type using ResxParser.xml format definition

valid resx syntax

Files that use the xml parser and the ResxParser.xml format definition are expected to have valid resx syntax

.resx uses the xml parser type

When defining a project containing LRM Standard .resx resource files, there is no need to define a <parser-type> as the xml parser will always be used along with the ResxParser.xml format definition.

unique file extension needs to define xml parser type and copy over the ResxParser.xml format definition

If a unique file extension is a valid resx file, then:

  • In the Project definition xml file, <parser-type> should be xml
  • After creating the project
    • Copy over the ResxParser.xml format definition located in ../lrm-server-<x.x>/samples/XmlParserExamples into the ../L10nStreamlining/<group>/projects/<project>/config folder
    • Rename file ResxParser.xml to xmlParser.xml

Sample LRM Project Definition File for .resx

 <?xml version="1.0" encoding="UTF-8"?>
 <lrmconf>
  <model-version>1.0.0</model-version>
  <project-name>WinApp</project-name>
       <project-desc>Lingoport.WinApp is configured to support resx resource files</project-desc>
 <group-name>Lingoport</group-name>
 <top-level-dir>/var/lib/jenkins/jobs/Lingoport.WinApp/workspace</top-level-dir>
 <detect-errors>
   <missed-trans-error>0</missed-trans-error>
   <parameter-mismatch-error>1</parameter-mismatch-error>
 </detect-errors>
 <track-back-locale>br</track-back-locale>
 <pseudo-locale>eo</pseudo-locale>
 <target-locales>
   <locale>de</locale>
   <locale>fr</locale>
   <locale>ja</locale>
 </target-locales>
 <default-locale>en_US</default-locale>
 <resource-extensions>
    <resource-extension>
     <!-- parser-type not needed since .resx is a standard LRM extension that maps to the xml parser type -->
     <extension>resx</extension>
     <file-name-pattern>*.l-c-v</file-name-pattern>
     <use-pattern-on-dflt-locale>0</use-pattern-on-dflt-locale>                
     <file-location-pattern></file-location-pattern>
     <use-location-pattern-on-dflt-locale>0</use-location-pattern-on-dflt-locale>
     <base-file-encoding>UTF-8</base-file-encoding>
     <localized-file-encoding>UTF-8</localized-file-encoding>
     <parameter-regex-pattern><![CDATA[%[ds]|%\d+\$[ds]|%\{\w+\}]]></parameter-regex-pattern>
   </resource-extension>
   <resource-extension>
     <!-- parser-type is required because .myext is not a standard LRM extension -->
     <extension>myext</extension>
     <!-- Once the project is created, the ResxParser.xml, located in the samples/XmlParserExamples, 
       needs to copied over the project's config folder and renamed xmlParser.xml  -->
     <parser-type>xml</parser-type>
     <file-name-pattern>*.l-c-v</file-name-pattern>
     <use-pattern-on-dflt-locale>0</use-pattern-on-dflt-locale>                
     <file-location-pattern></file-location-pattern>
     <use-location-pattern-on-dflt-locale>0</use-location-pattern-on-dflt-locale>
     <base-file-encoding>UTF-8</base-file-encoding>
     <localized-file-encoding>UTF-8</localized-file-encoding>
     <parameter-regex-pattern><![CDATA[%[ds]|%\d+\$[ds]|%\{\w+\}]]></parameter-regex-pattern>
   </resource-extension>
 </resource-extensions>
 <dirset>
   <includes>
     <include-dir-file>**/**</include-dir-file>
   </includes>
    <excludes>
     <exclude-dir-file>**/source/bin/**</exclude-dir-file>
   </excludes>
 </dirset>
 </lrmconf>