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;
    }
  }
Esempio n. 2
0
  /*
   * Internal initialization method.  Handles initialization which
   * is common to both public methods.
   */
  private static void initInternal(String s) {
    assert !initialized;
    initialized = true;
    // Retain the original one:
    systemDefaultLocale = Locale.getDefault();

    if ((!"".equals(s)) && (s != null)) {
      setLocale(s);
    } else {
      setLocale(
          new Locale(
              System.getProperty("user.language", "en"), System.getProperty("user.country", "")));
    }

    // TODO: This is using internal knowledge of GEF.  It should
    // handle this itself. - tfm
    Localizer.addResource("GefBase", "org.tigris.gef.base.BaseResourceBundle");
    Localizer.addResource("GefPres", "org.tigris.gef.presentation.PresentationResourceBundle");
  }
Esempio n. 3
0
  /**
   * Initialize the locale.
   *
   * @param locale a string with the locale
   */
  public static void init(String locale) {
    //        assert !initialized; // GUITestActionOpenProject fails over this...
    initialized = true;

    // Retain the original one:
    systemDefaultLocale = Locale.getDefault();

    if ((!"".equals(locale)) && (locale != null)) {
      setLocale(locale);
    } else {
      setLocale(
          new Locale(
              System.getProperty("user.language", "en"), System.getProperty("user.country", "")));
    }

    /* TODO: This is using internal knowledge of GEF.  It should
     * handle this itself. - tfm
     * MVW: Move into something like Main.initGEF() */
    Localizer.addResource("GefBase", "org.tigris.gef.base.BaseResourceBundle");
    Localizer.addResource("GefPres", "org.tigris.gef.presentation.PresentationResourceBundle");
  }