Pass String Literals

This topic applies to

Applies to

Denali | Elbrus | Kilimanjaro | Mont Blanc | SuiteCommerce Advanced | Vinson

Important

If you are localizing text using an extension for SuiteCommerce Standard or SuiteCommerce Advanced, see Localize Text in an Extension.


In the following code the string literal, Country is required, is translated to Se requiere pais when the site’s language is set to Spanish. This correlates to the JSON name-value pair defined in the SC.Translations array of the es_ES.js file within the application’s Languages folder.

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

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

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

SC.Translations = {
      ...
"Continue Shopping":"Continuar comprando",  
"Continue Shopping on our $(0)":"Continuar comprando en nuestro $(0)",  
"Country is required":"Se requiere pais",  
"Credit Card Number is invalid":"Numero de tarjeta de credito no valido",  
"Credit Card type is not supported":"No se admite el tipo de tarjeta de credito",
      ...
}; 

Note

Values from the SC.Translations arrays are passed off to a translation function. Therefore, there may not always be a direct relationship between the values set in the SC.Translations array for a specified language and the actual values displayed in your web store.


Within SuiteCommerce, many string literals are translated on the client side using the _.translate() function. When a specific language is set for a website, string literals wrapped in any _.translate() functions are replaced with language specific strings. These strings are retrieved from name-value pairs defined in the SC.Translations arrays within the JavaScript files located in the languages directory.

Language JavaScript files are located in the languages subfolder for each application module. For example, Modules > suite_commerce > ShoppingApplication.x.x.x > Languages. In the final Distribution folder, these files are located in the languages subfolder at the root level.

Note

If a literal wrapped in a _.translate() function does not have a corresponding name-value pair in the SC.Translations array for the active language, that literal is not replaced.


For example, in the following code the string literal Country is required is translated to Se requiere pais when the site’s active language is Spanish. This correlates to the JSON name-value pair defined in the SC.Translations array of the es_ES.js file within the languages folder.

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

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

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

SC.Translations = {
      ...
"Continue Shopping":"Continuar comprando",  
"Continue Shopping on our $(0)":"Continuar comprando en nuestro $(0)",  
"Country is required":"Se requiere pais",  
"Credit Card Number is invalid":"Numero de tarjeta de credito no valido",  
"Credit Card type is not supported":"No se admite el tipo de tarjeta de credito",
      ...
}; 

Note

Values from the SC.Translations arrays are passed off to a translation function. Therefore, a direct relationship may not always exist between the values set in the SC.Translations array for a specified language and the actual values displayed in your web store.