Adding Translated Content in Advanced Printouts

With the Translation Collection API, you can use FreeMarker code to add translated content in advanced printouts. For example, you could access the Translation Collection to display a localized disclaimer or a greeting. You can use one printing template that pulls the appropriate translation for all languages from the collection to produce translations in multiple languages. Currently, you can do this in source code mode only.

When working with Translation Collections data, you have the following options:

          <#assign handle = nstranslation.load({
   "collections":[{
     "alias": "myAlias",
     "collection": "custcollection_testcol",
     "keys": ["GREETINGS", "INTERVAL_1_TO_2]}],
   "locales" : [
      nstranslation.Locale.cs_CZ,
      nstranslation.Locale.en_US
      ]
})> 

        

Use Default Locale

The first locale specified in load is the default. In the previous example, that would be cs_CZ. So, if you use the following, the resulting greeting will be Ahoj:

          ${handle.myAlias.GREETINGS} 

        

Get Translation for a Different Locale

To get translation from handle for a different locale than what's in the locale's list, use nstranslation.selectLocale(). You can use this if you want to translate into the specified language one time only. For example, if you use the following, the resulting greeting will be Hello:

          ${nstranslation.selectLocale({"handle": handle, "locale": nstranslaton.Locale.en_US}).myAlias.GREETINGS} 

        

Translate Multiple Strings to Same Language

When you want to translate multiple strings into the same language, you should store localized handle into a variable, like this:

          <#assign englishHandle = nstranslation.selectLocale({"handle": handle, "locale" : nstranslation.Locale.en_US})> 

        

For example, you could then use it as follows to get a greeting of Hello:

          ${englishHandle.myAlias.GREETINGS} 

        

For more information, see translation.load(options).

Example of String with Language Translation

In the following example, we have a string that will get the expected count of orders within a specified range. From the entry in the Source String field, you can see there are two placeholders ( {1} and {2} ) for the range of numbers to include in the output. The Key is entered in the ID field, and the string translation in the Czech language is shown in the Translation field.

In this example, the default locale is set to display in English (US). When printing the document, you can specify the output be printed in Czech, rather than in the default language.

Source String: Expected count of orders is between {1} and {2}.

Key: EXPECTED_COUNT_OF_ORDERS_BETWEEN_1_2

Advanced PDF/HTML Templates example of string with language translation.

To use this string in the template source code, enter a line similar to the following:

            ${nstranslation.get({"collection":"custcollection_testcol", "key": "EXPECTED_COUNT_OF_ORDERS_BETWEEN_1_2"})({"params":["10", "15"]})} >
${englishHandle.myAlias.INTERVAL_1_TO_2({"params":["10", "15"]})} 

          

The parameters provided for the place holders are 10 and 15.

Result:

Expected count of orders is between 10 and 15

For more information, see Translation Collections Overview.

For more information, see N/translation Module.

Related Topics

General Notices