Esempio n. 1
0
  /**
   * The main function of this class that localizes strings.
   *
   * @param key The key to localize.
   * @return The localized String.
   */
  public static String localize(String key) {
    /* This is needed for the JUnit tests.
     * Otherwise a "assert initialized" would suffice. */
    if (!initialized) {
      init("en");
    }

    if (key == null) {
      throw new IllegalArgumentException("null");
    }

    String name = getName(key);
    if (name == null) {
      return Localizer.localize("UMLMenu", key);
    }

    loadBundle(name);

    ResourceBundle bundle = bundles.get(name);
    if (bundle == null) {
      LOG.debug("Bundle (" + name + ") for resource " + key + " not found.");
      return key;
    }

    try {
      return bundle.getString(key);
    } catch (MissingResourceException e) {
      LOG.debug("Resource " + key + " not found.");
      return key;
    }
  }