Class Dictionary

java.lang.Object
com.google.gwt.i18n.client.Dictionary

public final class Dictionary extends Object
Provides dynamic string lookup of key/value string pairs defined in a module's host HTML page. Each unique instance of Dictionary is bound to a named JavaScript object that resides in the global namespace of the host page's window object. The bound JavaScript object is used directly as an associative array.

For example, suppose you define the following JavaScript object in your host page:

var CurrentTheme = {
  highlightColor: "#FFFFFF",
  shadowColor: "#808080",
  errorColor: "#FF0000",
  errorIconSrc: "stopsign.gif"
};
You can then use a Dictionary to access the key/value pairs above:
public void useThemeDictionary() {
  Dictionary theme = Dictionary.getDictionary("CurrentTheme");

  String highlightColor = theme.get("highlightColor");
  String shadowColor = theme.get("shadowColor");
  applyShadowStyle(highlightColor, shadowColor);

  String errorColor = theme.get("errorColor");
  String errorIconSrc = theme.get("errorIconSrc");
  Image errorImg = new Image(errorIconSrc);
  showError(errorColor, errorImg);
}

Unlike the family of interfaces that extend Localizable which support static internationalization, the Dictionary class is fully dynamic. As a result, a variety of error conditions (particularly those involving key mismatches) cannot be caught until runtime. Similarly, the GWT compiler is unable discard unused dictionary values since the structure cannot be statically analyzed.

A Caveat Regarding Locale

The module's host page completely determines the mappings defined for each dictionary without regard to the locale client property. Thus, Dictionary is the most flexible of the internationalization types and may provide the simplest form of integration with existing localization systems which were not specifically designed to use GWT's locale client property.

See Localizable for background on the locale client property.

Required Module

Modules that use this interface should inherit com.google.gwt.i18n.I18N.
<module>
  <!-- other inherited modules, such as com.google.gwt.user.User -->
  <inherits name="com.google.gwt.i18n.I18N"/>
  <!-- additional module settings -->
</module>