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:
-
nstranslation.load - loads strings for specific keys of specific collections for specific locales. The locales parameter is optional. If not defined, the current locale from FreeMarker is used.
In the example that follows, strings with the keys GREETINGS and INTERVAL_1_TO_2 load from the custcollection_testcol collection for the cs_CZ and en_US locales. The translation for cs_CZ contains "Ahoj" and translation for en_US contains "Hello"
<#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).
-
nstranslation.get - use the collection to translate a single string to one selected locale one time only. The locale parameter is optional. If not defined, the current locale from FreeMarker is used.
For example, to return a greeting of Hello, you can access the string in the collection using:
${nstranslation.get({"collection":"custcollection_testcol", "key": "GREETINGS", "locale": nstranslation.Locale.en_US})}
For more information, see translation.get(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
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
- Source Code Editing in the Template Editor
- Source Code Editing to Customize Advanced Templates
- Syntax for Advanced Template Fields
- Setting a Template to Use a Font Unavailable in NetSuite
- Languages for Printed Forms that Use Advanced Templates
- Adding Striping to Line Items in Advanced Templates
- Adding Page Breaks to Tables
- Printing Subsidiary Logo on Advanced Templates
- Adding Apply Sublist to Check Templates
- Using FreeMarker to Work with Hidden Fields Used in Advanced Templates
- Adding Bar Codes in Advanced Templates