Package com.ibm.icu.util

Examples of com.ibm.icu.util.GlobalizationPreferences


   * @return the sorted list of ULocale instances
   */
  @SuppressWarnings("unchecked")
  public static List<ULocale> getProcessedLocaleList(String[] locales){
    if (locales == null) return getDefaultLocaleList();
    GlobalizationPreferences prefs = new GlobalizationPreferences();
   
    ArrayList<ULocale> ulocales = new ArrayList<ULocale>();
    for (String locale:locales){
      if (locale != null){
        try {
          ULocale ulocale = ULocale.forLanguageTag(locale);
          if (!ulocale.getLanguage().equals(""))
            ulocales.add(ulocale);
        } catch (Exception e) {
          // There can be intermittent problems with the internal
          // functioning of the ULocale class with some
          // language tags; best to just log these and continue
          _logger.error("icu4j:ULocale.forLanguageTag("+locale+") threw Exception:",e);
        }
      }
    } 
    if (ulocales.isEmpty()) return getDefaultLocaleList();
    prefs.setLocales(ulocales.toArray(new ULocale[ulocales.size()]));
    return prefs.getLocales();
  }
View Full Code Here


   * Gets the default locales list
   * @return a list of ULocale instances for the default locale
   */
  @SuppressWarnings("unchecked")
  protected static List<ULocale> getDefaultLocaleList(){
    GlobalizationPreferences prefs = new GlobalizationPreferences();
    return prefs.getLocales();
  }
View Full Code Here

  @Test
  public void testProcessElementsByDefaultLocales() {
    // This will hopefully be independent of the real locale where the test
    // is run
    // Determine the "real" locales.
    GlobalizationPreferences prefs = new GlobalizationPreferences();
    ArrayList<ULocale> locales = (ArrayList<ULocale>)prefs.getLocales();
    assertNotNull("Locales array is not null", locales);

    // Set up a dummy list of strings. Last one will be the
    // correct one.
    LocalizedString[] elements = new LocalizedString[4];
View Full Code Here

        assertEquals("Hello World", internationalString.getLocalizedString("en").getValue());
    }

    @Test
    public void defaultLocale() {
        GlobalizationPreferences prefs = new GlobalizationPreferences();

        InternationalString internationalString = new InternationalString();
        internationalString.setLocalizedString(new LocalizedString("Hello World", "en"));
        internationalString.setLocalizedString(new LocalizedString("Hallo Wereld", "nl"));
        internationalString.setLocalizedString(new LocalizedString("你好世界", "cn"));

        // The actual test depends on the system default locale
        String defaultLocale = prefs.getLocale(0).toLanguageTag();
        if (defaultLocale.contains("cn"))
            assertEquals("你好世界", internationalString.getDefaultLocalizedString().getValue());
        if (defaultLocale.equals("nl"))
            assertEquals("Hallo Wereld", internationalString.getDefaultLocalizedString().getValue());
        if (defaultLocale.contains("en"))
View Full Code Here

     * @return
     */
    public static List<ULocale> getProcessedLocaleList(String[] locales) {
        if (locales == null)
            return getDefaultLocaleList();
        GlobalizationPreferences prefs = new GlobalizationPreferences();

        ArrayList<ULocale> ulocales = new ArrayList<ULocale>();
        for (String locale : locales) {
            if (locale != null) {
                try {
                    ULocale ulocale = ULocale.forLanguageTag(locale);
                    if (!ulocale.getLanguage().equals(""))
                        ulocales.add(ulocale);
                } catch (Exception e) {
                    // There can be intermittent problems with the internal
                    // functioning of the ULocale class with some
                    // language tags; best to just log these and continue
                    _logger.error("icu4j:ULocale.forLanguageTag(" + locale + ") threw Exception:", e);
                }
            }
        }
        if (ulocales.isEmpty())
            return getDefaultLocaleList();
        prefs.setLocales(ulocales.toArray(new ULocale[ulocales.size()]));
        return prefs.getLocales();
    }
View Full Code Here

     * Gets the default locales list
     *
     * @return
     */
    protected static List<ULocale> getDefaultLocaleList() {
        GlobalizationPreferences prefs = new GlobalizationPreferences();
        return prefs.getLocales();
    }
View Full Code Here

   * @param locales
   * @return the sorted list of ULocale instances
   */
  public static List<ULocale> getProcessedLocaleList(String[] locales){
    if (locales == null) return getDefaultLocaleList();
    GlobalizationPreferences prefs = new GlobalizationPreferences();
   
    ArrayList<ULocale> ulocales = new ArrayList<ULocale>();
    for (String locale:locales){
      if (locale != null){
        try {
          ULocale ulocale = ULocale.forLanguageTag(locale);
          if (!ulocale.getLanguage().equals(""))
            ulocales.add(ulocale);
        } catch (Exception e) {
          // There can be intermittent problems with the internal
          // functioning of the ULocale class with some
          // language tags; best to just log these and continue
          _logger.error("icu4j:ULocale.forLanguageTag("+locale+") threw Exception:",e);
        }
      }
    } 
    if (ulocales.isEmpty()) return getDefaultLocaleList();
    prefs.setLocales(ulocales.toArray(new ULocale[ulocales.size()]));
    return prefs.getLocales();
  }
View Full Code Here

  /**
   * Gets the default locales list
   * @return a list of ULocale instances for the default locale
   */
  protected static List<ULocale> getDefaultLocaleList(){
    GlobalizationPreferences prefs = new GlobalizationPreferences();
    return prefs.getLocales();
  }
View Full Code Here

        String baseName = "com.ibm.icu.dev.data.resources.TestDataElements";
        ResourceBundle rb;

        logln("Get a resource bundle " + baseName +
                " using GlobalizationPreferences initialized by locales - en_GB, en_US");
        GlobalizationPreferences gp = new GlobalizationPreferences();
        ULocale[] locales = new ULocale[2];
        locales[0] = new ULocale("en_GB");
        locales[1] = new ULocale("en_US");
        gp.setLocales(locales);

        try {
            rb = gp.getResourceBundle(baseName);
            String str = rb.getString("from_en_US");
            if (!str.equals("This data comes from en_US")) {
                errln("FAIL: from_en_US is not from en_US bundle");
            }
        } catch (MissingResourceException mre) {
            errln("FAIL: Missing resouces");
        }

        gp.reset();

        logln("Get a resource bundle " + baseName +
        " using GlobalizationPreferences initialized by locales - ja, en_US_California");

        locales = new ULocale[2];
        locales[0] = new ULocale("ja");
        locales[1] = new ULocale("en_US_California");
        gp.setLocales(locales);
       
        try {
            rb = gp.getResourceBundle(baseName, Thread.currentThread().getContextClassLoader());
            String str = rb.getString("from_en_US");
            if (!str.equals("This data comes from en_US")) {
                errln("FAIL: from_en_US is not from en_US bundle");
            }
        } catch (MissingResourceException mre) {
            errln("FAIL: Missing resouces");
        }

        logln("Get a resource bundle which does not exist");
        boolean bException = false;
        try {
            rb = gp.getResourceBundle("foo.bar.XXX");
        } catch (MissingResourceException mre) {
            logln("Missing resource exception for getting resource bundle - foo.bar.XXX");
            bException = true;
        }
        if (!bException) {
View Full Code Here

            errln("FAIL: MissingResourceException must be thrown for RB - foo.bar.XXX");
        }
    }

    public void TestTerritory() {
        GlobalizationPreferences gp = new GlobalizationPreferences();

        // Territory for unsupported language locale
        logln("Set locale - ang");
        gp.setLocale(new ULocale("ang"));
        String territory = gp.getTerritory();
        if (!territory.equals("US")) {
            errln("FAIL: Territory is " + territory + " - Expected: US");
        }

        // Territory for language only locale "fr"
        logln("Set locale - fr");
        gp.setLocale(new ULocale("fr"));
        territory = gp.getTerritory();
        if (!territory.equals("FR")) {
            errln("FAIL: Territory is " + territory + " - Expected: FR");
        }


        // Set explicity territory
        logln("Set explicit territory - CA");
        gp.setTerritory("CA");
        territory = gp.getTerritory();
        if (!territory.equals("CA")) {
            errln("FAIL: Territory is " + territory + " - Expected: CA");
        }

        // Freeze
        logln("Freeze this object");
        gp.freeze();
       
        boolean bFrozen = false;
        try {
            gp.setTerritory("FR");
        } catch (UnsupportedOperationException uoe) {
            logln("setTerritory is blocked");
            bFrozen = true;
        }
        if (!bFrozen) {
            errln("FAIL: setTerritory must be blocked after frozen");
        }
        territory = gp.getTerritory();
        if (!territory.equals("CA")) {
            errln("FAIL: Territory is not CA");
        }

        // Safe clone
        GlobalizationPreferences gp1 = (GlobalizationPreferences)gp.cloneAsThawed();
        territory = gp1.getTerritory();
        if (!territory.equals("CA")) {
            errln("FAIL: Territory is " + territory + " - Expected: CA");
        }

        gp1.reset();
        ULocale[] locales = new ULocale[2];
        locales[0] = new ULocale("ja");
        locales[1] = new ULocale("zh_Hant_TW");
        logln("Set locales - ja, zh_Hant_TW");
        gp1.setLocales(locales);

        territory = gp1.getTerritory();
        if (!territory.equals("TW")) {
            errln("FAIL: Territory is " + territory + " - Expected: TW");
        }
    }
View Full Code Here

TOP

Related Classes of com.ibm.icu.util.GlobalizationPreferences

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.