StringDictionary

Abstract

This topic describes how to use the StringDictionary component in SPEAK.

You use the StringDictionary component to retrieve strings from the Sitecore dictionary.

The recommended way to add translatable text strings to a SPEAK application is to use configuration items. Configuration items are regular Sitecore items, and 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 and this component makes the dictionary strings available for client-side code.

You can add strings from the dictionary to the StringDictionary component in two ways:

  • You can point to one or more dictionary items. The StringDictionary component makes these dictionary items available.

  • You can specify one or more text strings (phrases). The StringDictionary component finds these phrases in the dictionary and makes the corresponding dictionary items available.

When you have created and configured a StringDictionary component, you can use it in JavaScript in your page. For example:

Sitecore.Resources.Dictionary["somePhrase"]

or

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

translate” returns the key (“somePhrase”) if it cannot find a translation. If you do not use “translate” you will get “undefined” in this case.

To configure a StringDictionary component:

  1. Create a configuration item based on the StringDictionary Parameters template, and open this configuration item in the Content Editor .

  2. Edit the Dictionary field in the configuration item. Select the dictionary items you need.

  3. Save the configuration item.

  4. Point the DataSource property of the StringDictionary component to this configuration item.

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

Note

You have to use the Content Editor to edit the configuration item. Sitecore Rocks does not work for this for the time being.