Pass String Literals

Documentation article about Pass String Literals

·3 min read·2 views·View Oracle Docs

This topic applies to the Kilimanjaro release of SCA and earlier. If you are localizing text using an extension, see Localize Text in an Extension.

In the following example, the string literal Country is required gets translated to Se requiere país when the site language is Spanish, matching the name-value pair in the SC.Translations array of the es_ES.js file.

_.translate() function used in Address.Model.js file:

javascript
validation: {
...
, country: { required: true, msg: _('Country is required').translate() }
...
}

Corresponding JSON used in ShoppingApplication@x.x.x >Languages > es_ES.js:

json
1SC.Translations = {
2 ...
3"Continue Shopping":"Continuar comprando",
4"Continue Shopping on our $(0)":"Continuar comprando en nuestro $(0)",
5"Country is required":"Se requiere país",
6"Credit Card Number is invalid":"Número de tarjeta de crédito no válido",
7"Credit Card type is not supported":"No se admite el tipo de tarjeta de crédito",
8 ...
9};

Note:

Values from the SC.Translations arrays go through a translation function, so the values you set in the array for a language might not always match exactly what shows up in your web store.

Many string literals are translated on the client side with the _.translate() function. When you set a specific language, string literals in _.translate() functions are replaced with language-specific strings from the SC.Translations arrays in the JavaScript language files.

The language JavaScript files are in the languages subfolder for each application module-for example, Modules > suite_commerce > ShoppingApplication.x.x.x > Languages. In the final Distribution folder, they're in the languages subfolder at the root.

Note:

If a literal in a _.translate() function doesn't match a name-value pair in the SC.Translations array for the active language, it won't be replaced.

For example, the string literal Country is required gets translated to Se requiere pais when Spanish is the active language, matching the name-value pair in the SC.Translations array of the es_ES.js file in the languages folder.

_.translate() function used in Address.Model.js file:

javascript
validation: {
...
, country: { required: true, msg: _('Country is required').translate() }
...
}

Corresponding JSON used in ShoppingApplication@x.x.x >Languages > es_ES.js:

javascript
1SC.Translations = {
2 ...
3"Continue Shopping":"Continuar comprando",
4"Continue Shopping on our $(0)":"Continuar comprando en nuestro $(0)",
5"Country is required":"Se requiere país",
6"Credit Card Number is invalid":"Número de tarjeta de crédito no válido",
7"Credit Card type is not supported":"No se admite el tipo de tarjeta de crédito",
8 ...
9};

Note:

Values from the SC.Translations arrays go to a translation function, so there might not always be a direct match between the values you set in the array and what actually appears in your web store.

Related Topics

General Notices

--- Context from https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_1516657590.html --- This section describes how to configure and manage localized text in an extension. An extension can include dictionary files with localized text, one file per language. When a user sets a language for a website, the application replaces string literals specified in the extension code with language-specific strings, which appear on the site.

Use the Extensibility API to replace string literals with the localized version in JavaScript files on the frontend and in SuiteScript files on the backend. Use the Handlebars translate custom helper to replace text with the localized version in template files. In addition, the Extensibility API includes a method to add additional translated string literals to the language-specific dictionary files.

translate() Method Syntax

The translate() method has the following syntax:

javascript
_('<string {0} {1}>').translate(0, 1)

In the above syntax, string is the string value to translate and 0 and 1 are optional parameters for values within string. Parameter values are optional but you can include an unlimited number, as required.

Custom Handlebars Helper

Use the custom Handlebars translate helper in the template file.

The translate custom helper uses the _.translate() function in HandlebarsExtra.js, which is located in the JavaScript subdirectory of the HandlebarsExtras application module.

To configure and manage localized text

Frequently Asked Questions (4)

How does the _.translate() function work with SC.Translations arrays?
The _.translate() function replaces string literals specified in its argument with language-specific strings from the SC.Translations arrays. This replacement occurs if a name-value pair matching the string literal exists in the array for the active language.
What happens if a string literal does not match any entries in the SC.Translations array?
If a string literal in a _.translate() function does not match any name-value pair in the SC.Translations array for the active language, it will not be replaced with a translated version.
Where are the language-specific JavaScript files located for the ShoppingApplication module?
The language-specific JavaScript files for the ShoppingApplication module are located in the Languages subfolder within each application module directory, such as Modules > suite_commerce > ShoppingApplication.x.x.x > Languages. In the final distribution, they are in the Languages subfolder at the root.
Does the Pass String Literals feature affect existing functionalities when migrating to a new NetSuite version?
The article does not provide information on whether migrating to a new NetSuite version affects existing functionalities of the Pass String Literals feature. Additional documentation or release notes may be required to determine impact.
Source: Pass String Literals Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in General

View all General articles →