Creating and updating a resource file

To load and format strings for different locales, you must create and update the resource file for the toolkit with translatable strings.

The resource file is an XML Localisation Interchange File Format (XLIFF) file. XLIFF is a standard XML format for capturing translatable text. The resource file is in a directory in the impl/nl/ directory, and it has a .xlf file extension (for example, impl/nl/en/en_US/MyResource.xlf).

In general, the format of XLIFF that is supported is the one that is supported by the underlying International Components for Unicode (ICU) version. However, it is better to base the resource file on Version 1.1 of the XLIFF standard.

The following example represents the file for the default language:
<xliff version="1.1" xmlns="urn:oasis:names:tc:xliff:document:1.1"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.1 _path_/xliff-core-1.1.xsd">
     <file datatype="plaintext" original="root.txt" source-language="en" target-language="en" xml:space="preserve">
          <body>
               <group>
                    <trans-unit id="1" extraData="MY_TOOLKIT_MESSAGE_1" resname="MSG0001">
                         <source>English/default: Tuple ''{0,number,integer}'' value is ''{1,number,integer}''.</source>
                    </trans-unit>
               </group>
          </body>
     </file>
</xliff>
The following example represents the file for a non-default language:
<xliff version="1.1" xmlns="urn:oasis:names:tc:xliff:document:1.1"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.1 _path_/xliff-core-1.1.xsd">
     <file datatype="plaintext" original="root.txt" source-language="en" target-language="tr" xml:space="preserve">
          <body>
               <group>
                    <trans-unit id="1" extraData="MY_TOOLKIT_MESSAGE_1" resname="MSG0001">
                         <source>English/default: Tuple ''{0,number,integer}'' value is ''{1,number,integer}''.</source>
                         <target>Turkish: Tuple ''{0,number,integer}'' value is ''{1,number,integer}''.</target>
                    </trans-unit>
               </group>
          </body>
     </file>
</xliff>

When the resources are built, the _path_ placeholder variable is replaced by the correct location of the schema. The xsi:schemaLocation attribute points to the XLIFF schema. The resource file can refer to a local file-based schema or a web-based schema. A local file-based schema has the benefit of improved processing performance. The preceding example refers to a local file-based schema that uses a _path_ placeholder variable to refer to the local path to the schema. This schema is provided with Teracloud® Streams. A web-based schema requires an internet connection to compile, and processing might be slow. The extraData attribute is optional from an XLIFF perspective, but is required to generate the associated C++ header or Perl module. Only one <file> element and one <group> element are supported in an XLIFF file.

If a resource file changes, the spl-make-toolkit command must be run to regenerate the headers. You can do this using one of the following options:
  • Invoking the spl-make-toolkit utility.
  • Using the SPL compiler (sc) to call the spl-make-toolkit utility.
A toolkit can have multiple resource bundles. Message identifiers that are specified within the resname elements must be unique across message bundles.
Restriction:
The C++ interface used by the generated header limits the number of substitution variables to 10. It is possible to load and format a message in C++ with an arbitrary number of arguments, but you need to use the FormattableMessage base class to build the message.