A target rule in a project specifies variables that are resolved when the target file location and name is needed.


For example, variable $(targetLocaleUnderscore)is resolved as it_IT for locale Italian (Italy).


There may be exceptions in some cases when the developers do not follow the standard rules.


Definition

Use the mappings-element in the .rigproj file to override the default behaviour.

  • The mappings-element is the root element. It has mapping element with the following characteristics.
    • Attributes:
      • id. The ID of the mapping rule.
      • var. This specifies the variable to which the mapping applies.
    • The map-element defines map-elements. Each map-element has the following attributes:
      • iso. The ISO language/locale. For example, de-DE, it-IT, en-US, en-UK, en, de, nl.
      • value. The replacement for that specific locale.
      • remove. Defines the number of characters that must be removed before and after the replacement. Examples:
        • -1: removes 1 character before the match.
        • -2: removes 2 characters before the match
        • 1: removes 1 character before the match.
        • 2: removes 1 character before the match.
        • -1,2: removes 1 character before and 2 after the match.
  • Targetrule-elements have an optional mapping-attribute. That mapping-attribute contains a comma-separated list of the mapping ids.


Example

This is best explained by means of an example. Assume that we have a project with 20 languages. For two variables, there are exceptions for it-IT and en-US.

  • Exception 1: variable $(targetLocaleUnderscore).
    • for Italian (Italy) it must be resolved as ita_ITA.
    • for English (United States), nothing shall be written and the preceeding underscore must be removed. This is typically the case when the source files must be overwritten.
  • Exception 2: variable $(sourceFileNameNoExt). Normally this is the name of the source file without the extension. E.g. "messages" if the filename is "messages.properties".
    • for Italian (Italy) it must be resolved as "ItalianMessages" instead of  "messages"


The project file for this example is:


<?xml version="1.0" encoding="utf-8"?>

<project name="Test" relbasepath=".">

  <parsersettings />

  <targetrules>

    <targetrule id="TR" mapping="map1,map2">targets\$(sourceFileNameNoExt)_$(targetLocaleUnderscore).properties</targetrule>

  </targetrules>

  <mappings>

    <mapping id="map1" var="targetLocaleUnderscore">

      <map iso="it-IT" value="ita_ITA" />

      <map iso="en-US" value="" remove="-1" />

    </mapping>

    <mapping id="map2" var="sourceFileNameNoExt">

      <map iso="it-IT" value="ItalianMessages" />

    </mapping>

  </mappings>

  <resources>

    <file relpath="source\messages.properties" guid="MSG" parser="properties" targetrule="TR" />

  </resources>

</project>


For example, the resolved variables for the following ISO codes are:

  • it-IT: targets\ItalianMessages_ita_ITA.properties
  • en-US: targets\messages.properties
  • de-DE: targets\messages.de_DE.properties