Locale GetString, GetKey, Translate Examples

This example demonstrates the various locale vipers which can be used to translate strings. Notice that the LocalizedStringResources table is used to lookup the specified string(s) and/or resource keys (=id). Within the cms manager, use Configure Localization to manage the entries within this table.

The locale.getstring() viper can be used to get the string (for the current culture) which is represented by the specified resource key/id. Use locale.culture.getstring() to get a culture specific translation for the specified resource key/id. In that case, pass a culture identifier as second parameter.

The locale.translate() viper translates the specified string into the current culture, whereas the locale.culture.translate() can be used to translate the specified string into a specific culture.

To determine the resource key/id for a specific string, use the locale.getkey() viper and specify the string using the default locale (usually en-US).

Both variants of the translate and getstring vipers (locale. and locale.culture.) also have an overload in which you can specify a list of arguments. The last three examples will clarify its purpose.

Smartsite SXML CopyCode image Copy Code
{locale.setlocale("nl-NL")}

{locale.getstring(EVC_MUSTATTEND)} <br/>
{locale.getkey("Must Attend")} <br/>
{locale.translate("Must Attend")} <br/>
{locale.culture.getstring("en-US", EVC_MUSTATTEND)} <br/>
{locale.culture.translate("nl-NL", "Must Attend")} <br/>

{locale.culture.getstring("en-US",RATING_RESULT)} <br/>
{locale.getstring(RATING_RESULT, 7, 10)} <br/>
{locale.translate("You rated this page with a {0} out of {1}.", 7, 10)}
Example Result CopyCode image Copy Code
Aanwezigheid vereist <br/> 
EVC_MUSTATTEND <br/> 
Aanwezigheid vereist <br/> 
Must Attend <br/> 
Aanwezigheid vereist <br/>
You rated this page with a {0} out of {1}. <br/> 
U heeft deze pagina beoordeeld met een 7 uit 10. <br/> 
U heeft deze pagina beoordeeld met een 7 uit 10.