Facilitate translation

Abstract

How to make it easier to translate SPEAK applications.

The recommended way to add translatable text strings to a SPEAK application is to use configuration items. Configuration items are regular Sitecore items.

There are procedures for translating text fields, however, you cannot use the configuration items from client-side JavaScript code. You can use a StringDictionary component instead. This component makes dictionary strings available for client-side code, and there are standard procedures for translating dictionary strings.

This topic describes both these procedures:

  • Use configuration items

  • Configure and use the StringDictionary component

  1. For the relevant control, create a configuration item using the "parameters" template.

  2. Place this item in PageSettings (convention).

  3. In the text fields of this item, enter the text for textual propertiess. For example, the "Text"and "Tooltip" fields. This can vary, so if you are in doubt, check the component reference.

  4. Point the DataSource property of the control to the configuration item.

You configure a StringDictionary component in this way:

  1. Create a configuration item based on the StringDictionary Parameters template.

  2. To point to items in the Sitecore dictionary, open the configuration item.

  3. In the Dictionary field, add the relevant dictionary items using the arrows >.

  4. Save the configuration item.

    Alternatively, you can specify phrases in the Phrases field. You can add multiple phrases by separating them with pipes (‘|’).

  5. Point the DataSource property of the StringDictionary component to the configuration item.

Now, you can use the strings from this configuration item in JavaScript on your page. For example:

Sitecore.Resources.Dictionary["somePhrase"]

or

Sitecore.Resources.Dictionary.translate("somePhrase")

The translate function returns the key (“somePhrase”) if it cannot find a translation. The default behavior is to return "undefined" in this case.