Difference between revisions of "LRM Properties Support"

From Lingoport Wiki
Jump to: navigation, search
(Example of Project Definition File)
(Example of Project Definition File)
Line 56: Line 56:
 
<lrmconf>
 
<lrmconf>
 
<model-version>2.0.11</model-version>
 
<model-version>2.0.11</model-version>
<!--Group name must match the group name option -->
 
 
<group-name>acme</group-name>
 
<group-name>acme</group-name>
 
<project-name>DemoJava</project-name>
 
<project-name>DemoJava</project-name>
<project-desc>This is a sample LRM Project definition file, configured to support Java properties files</project-desc>
+
<project-desc>This is a sample LRM Project definition file, configured to support Java properties files</project-desc>
  +
<top-level-dir>C:\acme\source</top-level-dir>
<!-- Example, linux -->
 
  +
<detect-errors>
<!--<top-level-dir>/var/lib/job/workspace/acme/source</top-level-dir>-->
 
<!-- Example, windows -->
+
<missed-trans-error>0</missed-trans-error>
  +
<parameter-mismatch-error>1</parameter-mismatch-error>
<top-level-dir>C:\acme\source</top-level-dir>
 
<detect-errors>
+
</detect-errors>
<!-- if set to '0' (false), then the 'missed translation' error will not be triggered
 
if the non-base file has the same text as the base file.
 
Missed Translation error will still occur if the base file has a different key or if
 
the base file has changed since it was last prepped. -->
 
<missed-trans-error>0</missed-trans-error>
 
<parameter-mismatch-error>1</parameter-mismatch-error>
 
</detect-errors>
 
<!--If you wish to create Track Back resource files, enter the Track Back locale such as `br`-->
 
<!--The track back locale is mutually exclusive of the base (default) locale, target locales and pseudo-locale-->
 
 
<track-back-locale>br</track-back-locale>
 
<track-back-locale>br</track-back-locale>
<!--If you wish to pseudo-localized your files enter a pseudo-locale-->
 
<!--The pseudo-locale is mutually exclusive of the base (default) locale and target locales-->
 
 
<pseudo-locale>eo</pseudo-locale>
 
<pseudo-locale>eo</pseudo-locale>
  +
<target-locales>
<!--Target locales are the locales where the corresponding resource files will be translated. -->
 
  +
<locale>fr_FR</locale>
<!--These target locales are mutually exclusive of the default locale-->
 
  +
<locale>fr_CA</locale>
<target-locales> <!-- set which locales are targeted for translation. -->
 
<locale>fr_FR</locale> <!-- French for France -->
 
<locale>fr_CA</locale> <!-- French Canadian -->
 
 
<locale>es_MX</locale>
 
<locale>es_MX</locale>
</target-locales>
+
</target-locales>
  +
<default-locale>en_US</default-locale> <!-- delineates which locale to translate from -->
<!--Default locale is the base locale. This is the locale where corresponding resource files will not be translated.-->
 
  +
<resources-extensions>
<!--The default locale is mutually exclusive of the target locales-->
 
<default-locale>en_US</default-locale> <!-- delineates which locale to translate from -->
 
<resources-extensions>
 
<!-- although only 1 resource extension is present in this file,
 
kits support multiple resource extensions. This necessitates both a
 
"<resource-extensions>" and "<resource-extension>" tag -->
 
<!--The file-name-pattern and/or file-location-pattern indicate the pattern of the-->
 
<!--localized file names (file-name-pattern) and the localized folder names (file-location-pattern).-->
 
<!--If the names contain the locale then a pattern of 1,c and v will be used.-->
 
<!--If the names contain the Locale ID then LCID will be used.-->
 
<!--Example pattern using locale-->
 
<!-- If your localized resource files use their locale in their names then the locale pattern will-->
 
<!-- be used where l stands for language; c for country; v for variant; and the characters between-->
 
<!-- are used as the separator characters.-->
 
<!-- <file-name-pattern>*_l_c_v</file-name-pattern>-->
 
<!--Example pattern using LCID (locale ID)-->
 
<!-- If your resource files are under a folder named 'resources' with an LCID suffix separated by an-->
 
<!-- underscore, then the pattern would be:-->
 
<!-- <file-location-pattern>resources_LCID</file-location-pattern>-->
 
 
<resource-extension>
 
<resource-extension>
<extension>properties</extension>
+
'''<extension>properties</extension>'''
<file-name-pattern>*_l_c_v</file-name-pattern>
+
'''<file-name-pattern>*_l_c_v</file-name-pattern>'''
  +
'''<use-pattern-on-dflt-locale>0</use-pattern-on-dflt-locale>'''
<!-- the tag below, when set to 1, will cause LRM to expect
 
  +
'''<file-location-pattern></file-location-pattern>'''
the locale to be specified within the filename of res.properties files -->
 
<use-pattern-on-dflt-locale>0</use-pattern-on-dflt-locale>
+
'''<use-location-pattern-on-dflt-locale>0</use-location-pattern-on-dflt-locale>'''
<file-location-pattern></file-location-pattern>
+
'''<base-file-encoding>UTF-8</base-file-encoding>'''
  +
'''<localized-file-encoding>UTF-8</localized-file-encoding>'''
<!-- There is no file location pattern -->
 
<use-location-pattern-on-dflt-locale>0</use-location-pattern-on-dflt-locale>
+
'''<parameter-regex-pattern><![CDATA[\{\w+\}|%[ds]]]></parameter-regex-pattern>'''
<base-file-encoding>UTF-8</base-file-encoding>
 
<localized-file-encoding>UTF-8</localized-file-encoding>
 
<!--Default pattern for properties is '![CDATA[\{\d+\}|%[ds]]]'-->
 
<parameter-regex-pattern><![CDATA[\{\w+\}|%[ds]]]></parameter-regex-pattern>
 
 
</resource-extension>
 
</resource-extension>
 
<resource-extension>
 
<resource-extension>
<extension>prop</extension>
+
'''<extension>''myext''</extension>'''
<parser-type>properties</parser-type>
+
'''''<parser-type>properties</parser-type>'''''
<file-name-pattern>*_l_c_v</file-name-pattern>
+
'''<file-name-pattern>*_l_c_v</file-name-pattern>'''
  +
'''<use-pattern-on-dflt-locale>0</use-pattern-on-dflt-locale>'''
<!-- the tag below, when set to 1, will cause LRM to expect
 
  +
'''<file-location-pattern></file-location-pattern>'''
the locale to be specified within the filename of res.properties files -->
 
<use-pattern-on-dflt-locale>0</use-pattern-on-dflt-locale>
+
'''<use-location-pattern-on-dflt-locale>0</use-location-pattern-on-dflt-locale>'''
<file-location-pattern></file-location-pattern>
+
'''<base-file-encoding>UTF-8</base-file-encoding>'''
  +
'''<localized-file-encoding>UTF-8</localized-file-encoding>'''
<!-- There is no file location pattern -->
 
<use-location-pattern-on-dflt-locale>0</use-location-pattern-on-dflt-locale>
+
'''<parameter-regex-pattern><![CDATA[\{\w+\}|%[ds]]]></parameter-regex-pattern>'''
<base-file-encoding>UTF-8</base-file-encoding>
 
<localized-file-encoding>UTF-8</localized-file-encoding>
 
<!--Default pattern for properties is '![CDATA[\{\d+\}|%[ds]]]'-->
 
<parameter-regex-pattern><![CDATA[\{\w+\}|%[ds]]]></parameter-regex-pattern>
 
 
</resource-extension>
 
</resource-extension>
 
</resources-extensions>
 
</resources-extensions>
 
<dirset>
 
<dirset>
<!--Define the search patterns to include and/or exclude. (Uses Apache Ant pattern search).-->
 
<!--Examples: -->
 
<!-- A. '**/*.properties' matches all .properties files/dirs in a directory tree.-->
 
<!-- B. 'test/a??.resx' matches all files/dirs which start with an 'a', -->
 
<!-- then two more characters and then '.resx', in a directory called test.-->
 
<!-- C. '**' matches everything in a directory tree. -->
 
<!-- '**/source/**/XYZ*' matches all files/dirs which start with 'XYZ'-->
 
<!-- and where there is a parent directory called source (e.g. 'abc/source/def/ghi/XYZ123'). -->
 
 
<includes>
 
<includes>
<!--Directories to include in the search for base resource files -->
+
<include-dir>**/src/**</include-dir>
<!--Examples: -->
 
<!-- <include-dir>**/source/**</include-dir>-->
 
 
</includes>
 
</includes>
 
<excludes>
 
<excludes>
<!--Directories or files to exclude in the search -->
 
<!--Examples: -->
 
<!-- <exclude-dir-file>**/source/bin/**</exclude-dir-file> -->
 
<!-- <exclude-dir-file>**/fileToIgnore.*</exclude-dir-file> -->
 
 
<exclude-dir-file>**/src/test/**</exclude-dir-file>
 
<exclude-dir-file>**/src/test/**</exclude-dir-file>
<exclude-dir-file>**/bin/**</exclude-dir-file>
 
<exclude-dir-file>**/target/**</exclude-dir-file>
 
<exclude-dir-file>**/.sonar-ide.properties</exclude-dir-file>
 
<exclude-dir-file>**/sonar-project.properties</exclude-dir-file>
 
<exclude-dir-file>**/test.properties</exclude-dir-file>
 
<exclude-dir-file>**/acceptance-test.properties</exclude-dir-file>
 
<exclude-dir-file>**/adminClient.properties</exclude-dir-file>
 
<exclude-dir-file>**/api-acceptance-service-accounts.properties</exclude-dir-file>
 
<exclude-dir-file>**/api-acceptance-users.properties</exclude-dir-file>
 
<exclude-dir-file>**/api-production-users.properties</exclude-dir-file>
 
 
</excludes>
 
</excludes>
 
</dirset>
 
</dirset>

Revision as of 20:09, 31 August 2017

How to setup LRM for .properties files as well as file extensions using the properties parser type

The encoding of a .properties file is ISO-8859-1, also known as Latin-1. All non-Latin-1 characters must be entered by using Unicode escape characters, e. g. \uHHHH where HHHH is a hexadecimal index of the character in the Unicode character set. This allows for using .properties files as resource bundles for localization. A non-Latin-1 text file can be converted to a correct .properties file by using the native2ascii tool that is shipped with the JDK or by using a tool, such as po2prop, that manages the transformation from a bilingual localization format into .properties escaping. For more information, please refer to : http://en.wikipedia.org/wiki/.properties


Naming Conventions

For optimum use of LRM, we strongly recommend that base files be named uniquely. If you have two files for instance, do not name them both resources.properties. Name them something different, like resources.properties and messages.properties

Properties files are used by applications written in many programming languages, such as Java. Java for instance has a full fledged standard infrastructure to handle resources (strings mostly) from properties files. Typically, an application will have many .properties base files located under different directories. The base file typically does not have a locale suffix as it serves as the default locale when resources are missing in another locale. See https://docs.oracle.com/javase/tutorial/essential/environment/properties.html .

For a base file named resources.properties, the corresponding French file will be in the same directory and the locale will be added to the file name: resources_fr.properties.

For example, for a few locales, the directory structure and file names would be:

 messages.properties
 messages_de.properties
 messages_es.properties
 messages_fr.properties
 messages_ru.properties
 messages_zh.properties

The bold file is the base file (U.S. English in this instance) translated into German, Spanish, French, Russian, and Chinese.

Example of .properties

  byTheFollowingAdministrator= by the following administrator: {0}
  artifactChangeNotification.Ownership=the request for notification of any change to a {0} you own.
  firstLastName={0} {1}
  user.confirm.delete=Are you sure you want to delete {0}?\\n\\nTHERE IS NO UNDO for deleting Users.
  user.editor.save.error=<strong>The User could not be saved.</strong><br/>\
  Please correct the errors identified below and click one of the "Save" buttons.<br/>
  #
  # bind and validation errors
  #
  User.invalidValueError.name=User Name must be a valid email address.

Note:

  • \ at the end of a string means the following line is part of that string, as in
  user.editor.save.error=<strong>The User could not be saved.</strong><br/>\
  Please correct the errors identified below and click one of the "Save" buttons.<br/>
  • Parameters are typically numbers in braces, as in
 firstLastName={0} {1}
  • Comments are specified with a # sign at the beginning of the line
 # bind and validation errors

Example of Project Definition File

<?xml version="1.0" encoding="UTF-8"?>
<lrmconf>
  <model-version>2.0.11</model-version>
  <group-name>acme</group-name>
  <project-name>DemoJava</project-name>
  <project-desc>This is a sample LRM Project definition file, configured to support Java properties files</project-desc>        
  <top-level-dir>C:\acme\source</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>fr_FR</locale> 
     <locale>fr_CA</locale> 
     <locale>es_MX</locale>
   </target-locales>
   <default-locale>en_US</default-locale> 
   <resources-extensions> 
     <resource-extension>
        <extension>properties</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[\{\w+\}|%[ds]]]></parameter-regex-pattern>
     </resource-extension>
     <resource-extension>
        <extension>myext</extension>
        <parser-type>properties</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[\{\w+\}|%[ds]]]></parameter-regex-pattern>
     </resource-extension>
  </resources-extensions>
  <dirset>
     <includes>
        <include-dir>**/src/**</include-dir>
     </includes>
     <excludes>
       <exclude-dir-file>**/src/test/**</exclude-dir-file>
     </excludes>
  </dirset>
</lrmconf>