Class Dictionary

java.lang.Object
org.gwtproject.i18n.client.Dictionary

public final class Dictionary
extends java.lang.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:

You can then use a Dictionary to access the key/value pairs above:

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 org.gwtproject.i18n.I18N.

  • Method Summary

    Modifier and Type Method Description
    java.lang.String get​(java.lang.String key)
    Get the value associated with the given Dictionary key.
    static Dictionary getDictionary​(java.lang.String name)
    Returns the Dictionary object associated with the given name.
    java.util.Set<java.lang.String> keySet()
    The set of keys associated with this dictionary.
    java.lang.String toString()  
    java.util.Collection<java.lang.String> values()
    Collection of values associated with this dictionary.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Method Details

    • getDictionary

      public static Dictionary getDictionary​(java.lang.String name)
      Returns the Dictionary object associated with the given name.
      Parameters:
      name -
      Returns:
      specified dictionary
      Throws:
      java.util.MissingResourceException
    • get

      public java.lang.String get​(java.lang.String key)
      Get the value associated with the given Dictionary key.

      We have to call Object.hasOwnProperty to verify that the value is defined on this object, rather than a superclass, since normal Object properties are also visible on this object.

      Parameters:
      key - to lookup
      Returns:
      the value
      Throws:
      java.util.MissingResourceException - if the value is not found
    • keySet

      public java.util.Set<java.lang.String> keySet()
      The set of keys associated with this dictionary.
      Returns:
      the Dictionary set
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • values

      public java.util.Collection<java.lang.String> values()
      Collection of values associated with this dictionary.
      Returns:
      the values