Difference between revisions of "LRM Properties Support"
(→Example of Project Definition File) |
(→Example of Project Definition File) |
||
(8 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | == How to setup LRM for .properties == |
+ | == 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. |
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 |
For more information, please refer to : http://en.wikipedia.org/wiki/.properties |
||
− | |||
== Naming Conventions == |
== Naming Conventions == |
||
Line 23: | Line 22: | ||
The bold file is the base file (U.S. English in this instance) translated into German, Spanish, French, Russian, and Chinese. |
The bold file is the base file (U.S. English in this instance) translated into German, Spanish, French, Russian, and Chinese. |
||
− | == Example of .properties== |
+ | == Example of .properties or a file extension using the ''properties'' parser type == |
<pre> |
<pre> |
||
byTheFollowingAdministrator= by the following administrator: {0} |
byTheFollowingAdministrator= by the following administrator: {0} |
||
Line 51: | Line 50: | ||
# bind and validation errors |
# bind and validation errors |
||
+ | == ''properties'' parser type == |
||
− | == Example of Project Definition File == |
||
+ | === valid properties syntax === |
||
+ | Files that use the ''properties'' parser are expected to have valid properties syntax |
||
+ | === .properties uses the ''properties'' parser type=== |
||
− | <?xml version="1.0" encoding="UTF-8"?> |
||
+ | When defining a project containing LRM Standard .properties resource files, there is no need to define a ''<parser-type>'' as the ''properties'' parser will always be used. |
||
− | <lrmconf> |
||
+ | |||
− | <model-version>2.0.11</model-version> |
||
+ | === unique file extension needs to define ''properties'' parser type === |
||
− | <!--Group name must match the group name option --> |
||
+ | If a unique file extension is a valid properties file, then the ''<parser-type>'' should be ''properties'' in the project definition file. |
||
− | <group-name>acme</group-name> |
||
+ | |||
− | <project-name>DemoJava</project-name> |
||
+ | == Example of Project Definition for Resources == |
||
− | <project-desc>This is a sample LRM Project definition file, configured to support Java properties files</project-desc> |
||
+ | The following is an example of properties resource file definitions. See [[Supported_Resource_Bundles#Resource_Extensions| resource extensions]] for more information. |
||
− | <!-- Example, linux --> |
||
+ | |||
− | <!--<top-level-dir>/var/lib/job/workspace/acme/source</top-level-dir>--> |
||
+ | <resources-extensions> |
||
− | <!-- Example, windows --> |
||
+ | <resource-extension> |
||
− | <top-level-dir>C:\acme\source</top-level-dir> |
||
+ | '''<extension>properties</extension>''' |
||
− | <detect-errors> |
||
+ | '''<file-name-pattern>*_l_c_v</file-name-pattern>''' |
||
− | <!-- if set to '0' (false), then the 'missed translation' error will not be triggered |
||
+ | '''<use-pattern-on-dflt-locale>0</use-pattern-on-dflt-locale>''' |
||
− | if the non-base file has the same text as the base file. |
||
+ | '''<file-location-pattern></file-location-pattern>''' |
||
− | Missed Translation error will still occur if the base file has a different key or if |
||
+ | '''<use-location-pattern-on-dflt-locale>0</use-location-pattern-on-dflt-locale>''' |
||
− | the base file has changed since it was last prepped. --> |
||
− | + | '''<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>''' |
||
− | </detect-errors> |
||
+ | </resource-extension> |
||
− | <!--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> |
||
− | <!--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> |
||
− | <!--Target locales are the locales where the corresponding resource files will be translated. --> |
||
− | <!--These target locales are mutually exclusive of the default 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> |
||
− | </target-locales> |
||
− | <!--Default locale is the base locale. This is the locale where corresponding resource files will not be translated.--> |
||
− | <!--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> |
+ | '''<extension>''myext''</extension>''' |
− | < |
+ | '''''<parser-type>properties</parser-type>''''' |
+ | '''<file-name-pattern>*_l_c_v</file-name-pattern>''' |
||
− | <!-- the tag below, when set to 1, will cause LRM to expect |
||
+ | '''<use-pattern-on-dflt-locale>0</use-pattern-on-dflt-locale>''' |
||
− | the locale to be specified within the filename of res.properties files --> |
||
− | < |
+ | '''<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>''' |
||
− | <!-- There is no file location pattern --> |
||
+ | '''<localized-file-encoding>UTF-8</localized-file-encoding>''' |
||
− | <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> |
||
+ | </resource-extension> |
||
− | <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> |
||
</resources-extensions> |
</resources-extensions> |
||
− | <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> |
||
− | <!--Directories to include in the search for base resource files --> |
||
− | <!--Examples: --> |
||
− | <!-- <include-dir>**/source/**</include-dir>--> |
||
− | </includes> |
||
− | <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>**/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> |
||
− | </dirset> |
||
− | </lrmconf> |
Latest revision as of 20:24, 18 September 2017
Contents
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 or a file extension using the properties parser type
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
properties parser type
valid properties syntax
Files that use the properties parser are expected to have valid properties syntax
.properties uses the properties parser type
When defining a project containing LRM Standard .properties resource files, there is no need to define a <parser-type> as the properties parser will always be used.
unique file extension needs to define properties parser type
If a unique file extension is a valid properties file, then the <parser-type> should be properties in the project definition file.
Example of Project Definition for Resources
The following is an example of properties resource file definitions. See resource extensions for more information.
<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>