コード例 #1
0
ファイル: LocaleTest.java プロジェクト: OzkanCiftci/jdk7u-jdk
  private void doTestDisplayNames(Locale inLocale, int compareIndex, boolean defaultIsFrench) {
    if (defaultIsFrench && !Locale.getDefault().getLanguage().equals("fr"))
      errln(
          "Default locale should be French, but it's really " + Locale.getDefault().getLanguage());
    else if (!defaultIsFrench && !Locale.getDefault().getLanguage().equals("en"))
      errln(
          "Default locale should be English, but it's really " + Locale.getDefault().getLanguage());

    for (int i = 0; i <= MAX_LOCALES; i++) {
      Locale testLocale = new Locale(dataTable[LANG][i], dataTable[CTRY][i], dataTable[VAR][i]);
      logln("  Testing " + testLocale + "...");

      String testLang;
      String testCtry;
      String testVar;
      String testName;

      if (inLocale == null) {
        testLang = testLocale.getDisplayLanguage();
        testCtry = testLocale.getDisplayCountry();
        testVar = testLocale.getDisplayVariant();
        testName = testLocale.getDisplayName();
      } else {
        testLang = testLocale.getDisplayLanguage(inLocale);
        testCtry = testLocale.getDisplayCountry(inLocale);
        testVar = testLocale.getDisplayVariant(inLocale);
        testName = testLocale.getDisplayName(inLocale);
      }

      String expectedLang;
      String expectedCtry;
      String expectedVar;
      String expectedName;

      expectedLang = dataTable[compareIndex][i];
      if (expectedLang.equals("") && defaultIsFrench) expectedLang = dataTable[DLANG_EN][i];
      if (expectedLang.equals("")) expectedLang = dataTable[DLANG_ROOT][i];

      expectedCtry = dataTable[compareIndex + 1][i];
      if (expectedCtry.equals("") && defaultIsFrench) expectedCtry = dataTable[DCTRY_EN][i];
      if (expectedCtry.equals("")) expectedCtry = dataTable[DCTRY_ROOT][i];

      expectedVar = dataTable[compareIndex + 2][i];
      if (expectedVar.equals("") && defaultIsFrench) expectedVar = dataTable[DVAR_EN][i];
      if (expectedVar.equals("")) expectedVar = dataTable[DVAR_ROOT][i];

      expectedName = dataTable[compareIndex + 3][i];
      if (expectedName.equals("") && defaultIsFrench) expectedName = dataTable[DNAME_EN][i];
      if (expectedName.equals("")) expectedName = dataTable[DNAME_ROOT][i];

      if (!testLang.equals(expectedLang))
        errln("Display language mismatch: " + testLang + " versus " + expectedLang);
      if (!testCtry.equals(expectedCtry))
        errln("Display country mismatch: " + testCtry + " versus " + expectedCtry);
      if (!testVar.equals(expectedVar))
        errln("Display variant mismatch: " + testVar + " versus " + expectedVar);
      if (!testName.equals(expectedName))
        errln("Display name mismatch: " + testName + " versus " + expectedName);
    }
  }
コード例 #2
0
 @Override
 public Locale findClosestMatch(Set<Locale> fromSet, Locale forLocale) {
   String variant = forLocale.getDisplayVariant();
   String country = forLocale.getCountry();
   String language = forLocale.getLanguage();
   Locale[] c = new Locale[4];
   if (null != variant && !variant.isEmpty()) {
     c[0] = forLocale;
   }
   if (null != country && !country.isEmpty()) {
     c[1] = new Locale(language, country);
   }
   if (null != language && !language.isEmpty()) {
     c[2] = new Locale(language);
   }
   c[3] = Locale.ROOT;
   for (Locale candidateLocale : c) {
     if (fromSet.contains(candidateLocale)) {
       return candidateLocale;
     }
   }
   // This code intentionally uses Locale.getDefault()
   // in order to behave in the same was as the default
   // resource bundle locale search mechanism.
   // source: http://docs.oracle.com/javase/tutorial/i18n/resbundle/concept.html
   Locale systemDefaultLocale = Locale.getDefault();
   if (!systemDefaultLocale.equals(forLocale)) {
     return findClosestMatch(fromSet, systemDefaultLocale);
   }
   return null;
 }
コード例 #3
0
ファイル: LocaleTest.java プロジェクト: ZeerDonker/robovm
  // http://b/2611311; if there's no display language/country/variant, use the raw codes.
  public void test_getDisplayName_unknown() throws Exception {
    Locale unknown = new Locale("xx", "YY", "Traditional");
    assertEquals("xx", unknown.getLanguage());
    assertEquals("YY", unknown.getCountry());
    assertEquals("Traditional", unknown.getVariant());

    assertEquals("xx", unknown.getDisplayLanguage());
    assertEquals("YY", unknown.getDisplayCountry());
    assertEquals("TRADITIONAL", unknown.getDisplayVariant());
    assertEquals("xx (YY,TRADITIONAL)", unknown.getDisplayName());
  }
コード例 #4
0
 /** @see {@link LocaleUtility#fromSpecification(String)} */
 @Test
 @Verifies(
     value = "should get locale from language code country code and variant",
     method = "fromSpecification(String)")
 public void fromSpecification_shouldGetLocaleFromLanguageCodeCountryCodeAndVariant()
     throws Exception {
   Locale locale = LocaleUtility.fromSpecification("en_US_Traditional_WIN");
   Assert.assertEquals(Locale.US.getLanguage(), locale.getLanguage());
   Assert.assertEquals(Locale.US.getCountry(), locale.getCountry());
   Assert.assertEquals("Traditional,WIN", locale.getDisplayVariant());
 }
コード例 #5
0
ファイル: LocaleTest.java プロジェクト: ZeerDonker/robovm
  // http://b/2611311; if there's no display language/country/variant, use the raw codes.
  public void test_getDisplayName_invalid() throws Exception {
    Locale invalid = new Locale("AaBbCc", "DdEeFf", "GgHhIi");

    assertEquals("aabbcc", invalid.getLanguage());
    assertEquals("DDEEFF", invalid.getCountry());
    assertEquals("GgHhIi", invalid.getVariant());

    // Android using icu4c < 49.2 returned empty strings for display language, country,
    // and variant, but a display name made up of the raw strings.
    // Newer releases return slightly different results, but no less unreasonable.
    assertEquals("aabbcc", invalid.getDisplayLanguage());
    assertEquals("", invalid.getDisplayCountry());
    assertEquals("DDEEFF_GGHHII", invalid.getDisplayVariant());
    assertEquals("aabbcc (DDEEFF,DDEEFF_GGHHII)", invalid.getDisplayName());
  }
コード例 #6
0
ファイル: TLocale.java プロジェクト: Syn4ck/jdownloader
  public String toString() {
    boolean hasVariant = locale.getVariant().length() > 0;
    boolean hasCountry = locale.getCountry().length() > 0;

    final StringBuilder sb = new StringBuilder();
    sb.append(locale.getDisplayLanguage(Locale.ENGLISH));
    if (hasVariant || hasCountry) {
      sb.append(" (");
    }

    if (hasCountry) {
      sb.append(locale.getDisplayCountry(Locale.ENGLISH));
    }

    if (hasVariant) {
      if (hasCountry) sb.append(", ");
      sb.append(locale.getDisplayVariant(Locale.ENGLISH));
    }

    if (hasVariant || hasCountry) {
      sb.append(")");
    }
    return sb.toString();
  }
コード例 #7
0
  private void recreateEditorsPanel() {
    myValuesPanel.removeAll();
    myValuesPanel.setLayout(new CardLayout());

    if (!myProject.isOpen()) return;
    JPanel valuesPanelComponent = new MyJPanel(new GridBagLayout());
    myValuesPanel.add(
        new JBScrollPane(valuesPanelComponent) {
          @Override
          public void updateUI() {
            super.updateUI();
            getViewport().setBackground(UIUtil.getPanelBackground());
          }
        },
        VALUES);
    myValuesPanel.add(myNoPropertySelectedPanel, NO_PROPERTY_SELECTED);

    List<PropertiesFile> propertiesFiles = myResourceBundle.getPropertiesFiles();

    GridBagConstraints gc =
        new GridBagConstraints(
            0,
            0,
            0,
            0,
            0,
            0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH,
            new Insets(5, 5, 5, 5),
            0,
            0);
    releaseAllEditors();
    myTitledPanels.clear();
    int y = 0;
    Editor previousEditor = null;
    Editor firstEditor = null;
    for (final PropertiesFile propertiesFile : propertiesFiles) {
      final Editor editor = createEditor();
      final Editor oldEditor = myEditors.put(propertiesFile, editor);
      if (firstEditor == null) {
        firstEditor = editor;
      }
      if (previousEditor != null) {
        editor.putUserData(
            ChooseSubsequentPropertyValueEditorAction.PREV_EDITOR_KEY, previousEditor);
        previousEditor.putUserData(
            ChooseSubsequentPropertyValueEditorAction.NEXT_EDITOR_KEY, editor);
      }
      previousEditor = editor;
      if (oldEditor != null) {
        EditorFactory.getInstance().releaseEditor(oldEditor);
      }
      ((EditorEx) editor)
          .addFocusListener(
              new FocusChangeListener() {
                @Override
                public void focusGained(final Editor editor) {
                  mySelectedEditor = editor;
                }

                @Override
                public void focusLost(final Editor eventEditor) {
                  writeEditorPropertyValue(editor, propertiesFile, null);
                }
              });
      gc.gridx = 0;
      gc.gridy = y++;
      gc.gridheight = 1;
      gc.gridwidth = GridBagConstraints.REMAINDER;
      gc.weightx = 1;
      gc.weighty = 1;
      gc.anchor = GridBagConstraints.CENTER;

      Locale locale = propertiesFile.getLocale();
      List<String> names = new ArrayList<String>();
      if (!Comparing.strEqual(locale.getDisplayLanguage(), null)) {
        names.add(locale.getDisplayLanguage());
      }
      if (!Comparing.strEqual(locale.getDisplayCountry(), null)) {
        names.add(locale.getDisplayCountry());
      }
      if (!Comparing.strEqual(locale.getDisplayVariant(), null)) {
        names.add(locale.getDisplayVariant());
      }

      String title = propertiesFile.getName();
      if (!names.isEmpty()) {
        title += " (" + StringUtil.join(names, "/") + ")";
      }
      JComponent comp =
          new JPanel(new BorderLayout()) {
            @Override
            public Dimension getPreferredSize() {
              Insets insets = getBorder().getBorderInsets(this);
              return new Dimension(100, editor.getLineHeight() * 4 + insets.top + insets.bottom);
            }
          };
      comp.add(editor.getComponent(), BorderLayout.CENTER);
      comp.setBorder(IdeBorderFactory.createTitledBorder(title, true));
      myTitledPanels.put(propertiesFile, (JPanel) comp);

      valuesPanelComponent.add(comp, gc);
    }
    if (previousEditor != null) {
      previousEditor.putUserData(
          ChooseSubsequentPropertyValueEditorAction.NEXT_EDITOR_KEY, firstEditor);
      firstEditor.putUserData(
          ChooseSubsequentPropertyValueEditorAction.PREV_EDITOR_KEY, previousEditor);
    }

    gc.gridx = 0;
    gc.gridy = y;
    gc.gridheight = GridBagConstraints.REMAINDER;
    gc.gridwidth = GridBagConstraints.REMAINDER;
    gc.weightx = 10;
    gc.weighty = 1;

    valuesPanelComponent.add(new JPanel(), gc);
    selectionChanged();
    myValuesPanel.repaint();
    UIUtil.invokeAndWaitIfNeeded(
        new Runnable() {
          @Override
          public void run() {
            updateEditorsFromProperties();
          }
        });
  }
コード例 #8
0
ファイル: LocaleActivity.java プロジェクト: zieglerm/enh
  static String describeLocale(String name) {
    final StringBuilder result = new StringBuilder();
    result.append("<html>");

    final Locale locale = localeByName(name);

    result.append("<p>");
    append(result, "Display Name", locale.getDisplayName());
    append(result, "Localized Display Name", locale.getDisplayName(locale));

    if (locale.getLanguage().length() > 0) {
      String iso3Language = "(not available)";
      try {
        iso3Language = locale.getISO3Language();
      } catch (MissingResourceException ignored) {
      }

      result.append("<p>");
      append(result, "Display Language", locale.getDisplayLanguage());
      append(result, "Localized Display Language", locale.getDisplayLanguage(locale));
      append(result, "2-Letter Language Code", locale.getLanguage());
      append(result, "3-Letter Language Code", iso3Language);
    }
    if (locale.getCountry().length() > 0) {
      String iso3Country = "(not available)";
      try {
        iso3Country = locale.getISO3Country();
      } catch (MissingResourceException ignored) {
      }

      result.append("<p>");
      append(result, "Display Country", locale.getDisplayCountry());
      append(result, "Localized Display Country", locale.getDisplayCountry(locale));
      append(result, "2-Letter Country Code", locale.getCountry());
      append(result, "3-Letter Country Code", iso3Country);
    }
    if (locale.getVariant().length() > 0) {
      result.append("<p>");
      append(result, "Display Variant", locale.getDisplayVariant());
      append(result, "Localized Display Variant", locale.getDisplayVariant(locale));
      append(result, "Variant Code", locale.getVariant());
    }

    result.append("<p><b>Number Formatting</b>");
    describeNumberFormat(result, "Decimal", NumberFormat.getInstance(locale), 1234.5, -1234.5);
    describeNumberFormat(result, "Integer", NumberFormat.getIntegerInstance(locale), 1234, -1234);
    describeNumberFormat(
        result, "Currency", NumberFormat.getCurrencyInstance(locale), 1234.5, -1234.5);
    describeNumberFormat(result, "Percent", NumberFormat.getPercentInstance(locale), 12.3);

    boolean hasLocaleData = hasLocaleData();

    if (!hasLocaleData) {
      result.append("<p><b>Decimal Format Symbols</b>");
      NumberFormat nf = NumberFormat.getInstance(locale);
      if (nf instanceof DecimalFormat) {
        describeDecimalFormatSymbols(result, ((DecimalFormat) nf).getDecimalFormatSymbols());
      } else {
        result.append("(Didn't expect " + nf.getClass() + ".)");
      }
    }

    Date now =
        new Date(); // FIXME: it might be more useful to always show a time in the afternoon, to
    // make 24-hour patterns more obvious.
    result.append("<p><b>Date/Time Formatting</b>");
    describeDateFormat(
        result, "Full Date", DateFormat.getDateInstance(DateFormat.FULL, locale), now);
    describeDateFormat(
        result, "Long Date", DateFormat.getDateInstance(DateFormat.LONG, locale), now);
    describeDateFormat(
        result, "Medium Date", DateFormat.getDateInstance(DateFormat.MEDIUM, locale), now);
    describeDateFormat(
        result, "Short Date", DateFormat.getDateInstance(DateFormat.SHORT, locale), now);
    result.append("<p>");
    describeDateFormat(
        result, "Full Time", DateFormat.getTimeInstance(DateFormat.FULL, locale), now);
    describeDateFormat(
        result, "Long Time", DateFormat.getTimeInstance(DateFormat.LONG, locale), now);
    describeDateFormat(
        result, "Medium Time", DateFormat.getTimeInstance(DateFormat.MEDIUM, locale), now);
    describeDateFormat(
        result, "Short Time", DateFormat.getTimeInstance(DateFormat.SHORT, locale), now);
    result.append("<p>");
    describeDateFormat(
        result,
        "Full Date/Time",
        DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, locale),
        now);
    describeDateFormat(
        result,
        "Long Date/Time",
        DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale),
        now);
    describeDateFormat(
        result,
        "Medium Date/Time",
        DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, locale),
        now);
    describeDateFormat(
        result,
        "Short Date/Time",
        DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale),
        now);

    if (!hasLocaleData) {
      result.append("<p><b>Date Format Symbols</b><p>");
      DateFormat edf = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);
      DateFormatSymbols edfs = ((SimpleDateFormat) edf).getDateFormatSymbols();
      DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, locale);
      DateFormatSymbols dfs = ((SimpleDateFormat) df).getDateFormatSymbols();
      append(result, "Local Pattern Chars", dfs.getLocalPatternChars());
      append(result, "Am/pm", Arrays.toString(dfs.getAmPmStrings()));
      append(result, "Eras", Arrays.toString(dfs.getEras()));
      append(result, "Months", Arrays.toString(dfs.getMonths()));
      append(result, "Short Months", Arrays.toString(dfs.getShortMonths()));
      append(result, "Weekdays", Arrays.toString(dfs.getWeekdays()));
      append(result, "Short Weekdays", Arrays.toString(dfs.getShortWeekdays()));
    }

    result.append("<p><b>Calendar</b><p>");
    Calendar c = Calendar.getInstance(locale);
    int firstDayOfWeek = c.getFirstDayOfWeek();
    String firstDayOfWeekString = new DateFormatSymbols(locale).getWeekdays()[firstDayOfWeek];
    String englishFirstDayOfWeekString =
        new DateFormatSymbols(Locale.US).getWeekdays()[firstDayOfWeek];
    String firstDayOfWeekDetails = firstDayOfWeek + " '" + firstDayOfWeekString + "'";
    if (!englishFirstDayOfWeekString.equals(firstDayOfWeekString)) {
      firstDayOfWeekDetails += " (" + englishFirstDayOfWeekString + ")";
    }
    append(result, "First Day of the Week", firstDayOfWeekDetails);
    append(result, "Minimal Days in First Week", c.getMinimalDaysInFirstWeek());

    // If this locale specifies a country, check out the currency.
    // Languages don't have currencies; countries do.
    if (!locale.getCountry().equals("")) {
      result.append("<p><b>Currency</b><p>");
      try {
        Currency currency = Currency.getInstance(locale);
        append(result, "ISO 4217 Currency Code", currency.getCurrencyCode());
        append(
            result,
            "Currency Symbol",
            unicodeString(currency.getSymbol(locale)) + " (" + currency.getSymbol(Locale.US) + ")");
        append(result, "Default Fraction Digits", currency.getDefaultFractionDigits());
      } catch (IllegalArgumentException ex) {
        result.append(
            "<p>(This version of Android is unable to return a Currency for this Locale.)");
      }
    }

    result.append("<p><b>Data Availability</b><p>");
    appendAvailability(result, locale, "BreakIterator", BreakIterator.class);
    appendAvailability(result, locale, "Calendar", NumberFormat.class);
    appendAvailability(result, locale, "Collator", Collator.class);
    appendAvailability(result, locale, "DateFormat", DateFormat.class);
    appendAvailability(result, locale, "DateFormatSymbols", DateFormatSymbols.class);
    appendAvailability(result, locale, "DecimalFormatSymbols", DecimalFormatSymbols.class);
    appendAvailability(result, locale, "NumberFormat", NumberFormat.class);

    if (hasLocaleData) {
      result.append("<p><b>libcore.icu.LocaleData</b>");
      try {
        Object enUsData = getLocaleDataInstance(Locale.US);
        Object localeData = getLocaleDataInstance(locale);
        String[] previous;

        result.append("<p>");
        describeStringArray(result, "amPm", enUsData, localeData, null);
        describeStringArray(result, "eras", enUsData, localeData, null);

        result.append("<p>");
        previous = describeStringArray(result, "longMonthNames", enUsData, localeData, null);
        describeStringArray(result, "longStandAloneMonthNames", enUsData, localeData, previous);
        previous = describeStringArray(result, "shortMonthNames", enUsData, localeData, null);
        describeStringArray(result, "shortStandAloneMonthNames", enUsData, localeData, previous);
        previous = describeStringArray(result, "tinyMonthNames", enUsData, localeData, null);
        describeStringArray(result, "tinyStandAloneMonthNames", enUsData, localeData, previous);

        result.append("<p>");
        previous = describeStringArray(result, "longWeekdayNames", enUsData, localeData, null);
        describeStringArray(result, "longStandAloneWeekdayNames", enUsData, localeData, previous);
        previous = describeStringArray(result, "shortWeekdayNames", enUsData, localeData, null);
        describeStringArray(result, "shortStandAloneWeekdayNames", enUsData, localeData, previous);
        previous = describeStringArray(result, "tinyWeekdayNames", enUsData, localeData, null);
        describeStringArray(result, "tinyStandAloneWeekdayNames", enUsData, localeData, previous);

        result.append("<p>");
        describeString(result, "yesterday", enUsData, localeData);
        describeString(result, "today", enUsData, localeData);
        describeString(result, "tomorrow", enUsData, localeData);

        result.append("<p>");
        describeString(result, "timeFormat12", enUsData, localeData);
        describeString(result, "timeFormat24", enUsData, localeData);

        result.append("<p>");
        describeChar(result, "zeroDigit", enUsData, localeData);
        describeChar(result, "decimalSeparator", enUsData, localeData);
        describeChar(result, "groupingSeparator", enUsData, localeData);
        describeChar(result, "patternSeparator", enUsData, localeData);
        describeChar(result, "percent", enUsData, localeData);
        describeChar(result, "perMill", enUsData, localeData);
        describeChar(result, "monetarySeparator", enUsData, localeData);
        describeChar(result, "minusSign", enUsData, localeData);
        describeString(result, "exponentSeparator", enUsData, localeData);
        describeString(result, "infinity", enUsData, localeData);
        describeString(result, "NaN", enUsData, localeData);

      } catch (Exception ex) {
        result.append("(" + ex.getClass().getSimpleName() + " thrown: " + ex.getMessage() + ")");
        System.err.println(ex);
      }
    }

    return result.toString();
  }