Java Code Examples for java.util.Locale#getDisplayCountry()

The following examples show how to use java.util.Locale#getDisplayCountry() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CountriesNames.java    From EasyVPN-Free with GNU General Public License v3.0 6 votes vote down vote up
public static Map<String, String> getCountries() {
    Map<String, String> countries = new HashMap<String, String>();

    String[] isoCountries = Locale.getISOCountries();
    for (String country : isoCountries) {
        Locale locale = new Locale("", country);
        String iso = locale.getISO3Country();
        String code = locale.getCountry();
        String name = locale.getDisplayCountry();

        if (!"".equals(iso) && !"".equals(code)
                && !"".equals(name)) {
            countries.put(code, name);
        }
    }

    return countries;
}
 
Example 2
Source File: CurrencyTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static void checkCountryCurrency(String countryCode, String expected) {
    Locale locale = new Locale("", countryCode);
    Currency currency = Currency.getInstance(locale);
    String code = (currency != null) ? currency.getCurrencyCode() : null;
    if (!(expected == null ? code == null : expected.equals(code))) {
        throw new RuntimeException("Wrong currency for " +
                locale.getDisplayCountry() +
                ": expected " + expected + ", got " + code);
    }
}
 
Example 3
Source File: CurrencyTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static void checkCountryCurrency(String countryCode, String expected) {
    Locale locale = new Locale("", countryCode);
    Currency currency = Currency.getInstance(locale);
    String code = (currency != null) ? currency.getCurrencyCode() : null;
    if (!(expected == null ? code == null : expected.equals(code))) {
        throw new RuntimeException("Wrong currency for " +
                locale.getDisplayCountry() +
                ": expected " + expected + ", got " + code);
    }
}
 
Example 4
Source File: CountryUtil.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
private static void populateCountryListByCodes(List<Country> list, String[] codes) {
    for (String code : codes) {
        Locale locale = new Locale(LanguageUtil.getDefaultLanguage(), code, "");
        final String countryCode = locale.getCountry();
        String regionCode = getRegionCode(countryCode);
        final Region region = new Region(regionCode, getRegionName(regionCode));
        Country country = new Country(countryCode, locale.getDisplayCountry(), region);
        if (countryCode.equals("XK"))
            country = new Country(countryCode, getNameByCode(countryCode), region);
        list.add(country);
    }
}
 
Example 5
Source File: LocaleUtil.java    From nextreports-designer with Apache License 2.0 5 votes vote down vote up
public static List<Country> getCountries() {
	List<Country> countries = new ArrayList<Country>();
	Locale[] locales = Locale.getAvailableLocales();
	for (Locale locale : locales) {
		String iso = "NA";
		try {
			iso = locale.getISO3Country();
		} catch (MissingResourceException ex) {				
		}
		String code = locale.getCountry();
		String name = locale.getDisplayCountry();
		String language = locale.getLanguage();

		if (!"".equals(iso) && !"".equals(code) && !"".equals(name)) {				
			Country c = new Country(iso, code, name, language);
			if (!countries.contains(c)) {
				countries.add(c);
			}	
		}
	}

	Collections.sort(countries, new Comparator<Country>() {
		@Override
		public int compare(Country c1, Country c2) {
			 return Collator.getInstance().compare(c1.getName(), c2.getName());
		}
		
	});	
	return countries;
}
 
Example 6
Source File: CurrencyTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
static void checkCountryCurrency(String countryCode, String expected) {
    Locale locale = new Locale("", countryCode);
    Currency currency = Currency.getInstance(locale);
    String code = (currency != null) ? currency.getCurrencyCode() : null;
    if (!(expected == null ? code == null : expected.equals(code))) {
        throw new RuntimeException("Wrong currency for " +
                locale.getDisplayCountry() +
                ": expected " + expected + ", got " + code);
    }
}
 
Example 7
Source File: SpellcheckChatRoomDecorator.java    From Spark with Apache License 2.0 5 votes vote down vote up
private void languagestoLocales()
{
    String spellLanguage = SpellcheckManager.getInstance().getSpellcheckerPreference().getPreferences().getSpellLanguage();
    _languages = new HashMap<String, String>();
    Locale[] locales = Locale.getAvailableLocales();
    ArrayList<String> languages = SpellcheckManager.getInstance().getSupportedLanguages();
    for (int i = 0; i < languages.size(); i++) {
        for (final Locale locale : locales) {
            if (locale.toString().equals(languages.get(i))) {
                String label = locale.getDisplayLanguage(Locale
                        .getDefault());
                if (locale.getDisplayCountry(locale) != null
                        && locale.getDisplayCountry(locale).trim().length() > 0) {
                    label = label + "-"
                            + locale.getDisplayCountry(locale).trim();
                }
                _languages.put(label, languages.get(i));
                _languageSelection.addItem(label);
                if (languages.get(i).equals(spellLanguage))
                {
                    _languageSelection.setSelectedItem(label);
                }
                
            }
        }
    }
}
 
Example 8
Source File: CurrencyTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
static void checkCountryCurrency(String countryCode, String expected) {
    Locale locale = new Locale("", countryCode);
    Currency currency = Currency.getInstance(locale);
    String code = (currency != null) ? currency.getCurrencyCode() : null;
    if (!(expected == null ? code == null : expected.equals(code))) {
        throw new RuntimeException("Wrong currency for " +
                locale.getDisplayCountry() +
                ": expected " + expected + ", got " + code);
    }
}
 
Example 9
Source File: Helper.java    From smartcoins-wallet with MIT License 5 votes vote down vote up
public static String getSpinnertextCountry(String countryCode) {

        Locale locale = new Locale("", countryCode);
        try {
            Currency currency = Currency.getInstance(locale);
            return locale.getDisplayCountry() + " (" + currency.getCurrencyCode() + ")";
        } catch (Exception e) {

        }
        return "";
    }
 
Example 10
Source File: Bug4640234.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
* Compares the english timezone name and timezone name in specified locale
* @param timeZoneName - name of the timezone to compare
* @param locale - locale to test against english
* @return empty string when passed, descriptive error message in other cases
*/
private static String testTZ(String timeZoneName, Locale locale) {
    StringBuffer timeZoneResult = new StringBuffer("");
    TimeZone tz = TimeZone.getTimeZone(timeZoneName);
    sdfEn.setTimeZone(tz);
    sdfEnShort.setTimeZone(tz);
    sdfLoc.setTimeZone(tz);
    sdfLocShort.setTimeZone(tz);

    String en, enShort, loc, locShort;
    en = sdfEn.format(date);
    enShort = sdfEnShort.format(date);
    loc = sdfLoc.format(date);
    locShort = sdfLocShort.format(date);

    String displayLanguage = locale.getDisplayLanguage();
    String displayCountry = locale.getDisplayCountry();

    if (loc.equals(en)) {
        timeZoneResult.append("[");
        timeZoneResult.append(displayLanguage);
        if (!"".equals(displayCountry)) {
            timeZoneResult.append(" ");
            timeZoneResult.append(displayCountry);
        }
        timeZoneResult.append("] timezone \"");
        timeZoneResult.append(timeZoneName);
        timeZoneResult.append("\" long name \"" + en);
        timeZoneResult.append("\" not localized!\n");
    }

    if (!locShort.equals(enShort)) {
        timeZoneResult.append("[");
        timeZoneResult.append(displayLanguage);
        if (!"".equals(displayCountry)) {
            timeZoneResult.append(" ");
            timeZoneResult.append(displayCountry);
        }
        timeZoneResult.append("] timezone \"");
        timeZoneResult.append(timeZoneName);
        timeZoneResult.append("\" short name \"" + enShort);
        timeZoneResult.append("\" is localized \"");
        timeZoneResult.append(locShort);
        timeZoneResult.append("\"!\n");
    }
    return timeZoneResult.toString();
}
 
Example 11
Source File: GeneralPreferenceFragment.java    From V2EX with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getPreferenceManager().setSharedPreferencesName(
            Config.getConfig(ConfigRefEnum.CONFIG_PREFERENCE_SETTING_FILE));
    addPreferencesFromResource(R.xml.pref_general);

    ListPreference themePreference = (ListPreference) findPreference(
            getString(R.string.key_theme));
    themePreference.setSummary(Config.getConfig(ConfigRefEnum.CONFIG_THEME));

    ListPreference dateFormatPreference = (ListPreference)findPreference(
            getString(R.string.key_date_format));
    String[] dateEntries = new String[dateFormatPreference.getEntryValues().length];
    int i = 0;
    for (CharSequence s:dateFormatPreference.getEntryValues()){
        String date = TimeUtil.getDateNow(String.valueOf(s));
        dateEntries[i++] = date;
    }
    dateFormatPreference.setEntries(dateEntries);
    dateFormatPreference.setSummary(TimeUtil.getDateNow(Config.getConfig(
            ConfigRefEnum.CONFIG_DATE_FORMAT)));

    ListPreference localePreference = (ListPreference) findPreference(getString(R.string.key_local));
    String[] localesEntryValue = new String[Config.LOCAL_LIST.size()];
    String[] localesEntries= new String[Config.LOCAL_LIST.size()];
    int index = 0;
    for (Locale locale:Config.LOCAL_LIST){
        localesEntryValue[index] = locale.toString();
        localesEntries[index++] = locale.getDisplayCountry();
    }
    localePreference.setDefaultValue(localesEntryValue[0]);
    localePreference.setEntryValues(localesEntryValue);
    localePreference.setEntries(localesEntries);

    Preference clearCachePreference = findPreference(getString(R.string.clear_cache));
    clearCachePreference.setOnPreferenceClickListener(this::clearCache);
    clearCachePreference.setSummary("缓存大小 12 MB");
    findPreference(getString(R.string.key_home_tabs)).setOnPreferenceClickListener(preference -> {
        CustomTabActivity.start(getActivity());
        return false;
    });
}
 
Example 12
Source File: Bug4640234.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
* Compares the english timezone name and timezone name in specified locale
* @param timeZoneName - name of the timezone to compare
* @param locale - locale to test against english
* @return empty string when passed, descriptive error message in other cases
*/
private static String testTZ(String timeZoneName, Locale locale) {
    StringBuffer timeZoneResult = new StringBuffer("");
    TimeZone tz = TimeZone.getTimeZone(timeZoneName);
    sdfEn.setTimeZone(tz);
    sdfEnShort.setTimeZone(tz);
    sdfLoc.setTimeZone(tz);
    sdfLocShort.setTimeZone(tz);

    String en, enShort, loc, locShort;
    en = sdfEn.format(date);
    enShort = sdfEnShort.format(date);
    loc = sdfLoc.format(date);
    locShort = sdfLocShort.format(date);

    String displayLanguage = locale.getDisplayLanguage();
    String displayCountry = locale.getDisplayCountry();

    if (loc.equals(en)) {
        timeZoneResult.append("[");
        timeZoneResult.append(displayLanguage);
        if (!"".equals(displayCountry)) {
            timeZoneResult.append(" ");
            timeZoneResult.append(displayCountry);
        }
        timeZoneResult.append("] timezone \"");
        timeZoneResult.append(timeZoneName);
        timeZoneResult.append("\" long name \"" + en);
        timeZoneResult.append("\" not localized!\n");
    }

    if (!locShort.equals(enShort)) {
        timeZoneResult.append("[");
        timeZoneResult.append(displayLanguage);
        if (!"".equals(displayCountry)) {
            timeZoneResult.append(" ");
            timeZoneResult.append(displayCountry);
        }
        timeZoneResult.append("] timezone \"");
        timeZoneResult.append(timeZoneName);
        timeZoneResult.append("\" short name \"" + enShort);
        timeZoneResult.append("\" is localized \"");
        timeZoneResult.append(locShort);
        timeZoneResult.append("\"!\n");
    }
    return timeZoneResult.toString();
}
 
Example 13
Source File: LocaleTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
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);
    }
}
 
Example 14
Source File: LocaleTest.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
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);
    }
}
 
Example 15
Source File: LocaleTest.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
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);
    }
}
 
Example 16
Source File: Bug4640234.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
* Compares the english timezone name and timezone name in specified locale
* @param timeZoneName - name of the timezone to compare
* @param locale - locale to test against english
* @return empty string when passed, descriptive error message in other cases
*/
private static String testTZ(String timeZoneName, Locale locale) {
    StringBuffer timeZoneResult = new StringBuffer("");
    TimeZone tz = TimeZone.getTimeZone(timeZoneName);
    sdfEn.setTimeZone(tz);
    sdfEnShort.setTimeZone(tz);
    sdfLoc.setTimeZone(tz);
    sdfLocShort.setTimeZone(tz);

    String en, enShort, loc, locShort;
    en = sdfEn.format(date);
    enShort = sdfEnShort.format(date);
    loc = sdfLoc.format(date);
    locShort = sdfLocShort.format(date);

    String displayLanguage = locale.getDisplayLanguage();
    String displayCountry = locale.getDisplayCountry();

    if (loc.equals(en)) {
        timeZoneResult.append("[");
        timeZoneResult.append(displayLanguage);
        if (!"".equals(displayCountry)) {
            timeZoneResult.append(" ");
            timeZoneResult.append(displayCountry);
        }
        timeZoneResult.append("] timezone \"");
        timeZoneResult.append(timeZoneName);
        timeZoneResult.append("\" long name \"" + en);
        timeZoneResult.append("\" not localized!\n");
    }

    if (!locShort.equals(enShort)) {
        timeZoneResult.append("[");
        timeZoneResult.append(displayLanguage);
        if (!"".equals(displayCountry)) {
            timeZoneResult.append(" ");
            timeZoneResult.append(displayCountry);
        }
        timeZoneResult.append("] timezone \"");
        timeZoneResult.append(timeZoneName);
        timeZoneResult.append("\" short name \"" + enShort);
        timeZoneResult.append("\" is localized \"");
        timeZoneResult.append(locShort);
        timeZoneResult.append("\"!\n");
    }
    return timeZoneResult.toString();
}
 
Example 17
Source File: Bug4640234.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
* Compares the english timezone name and timezone name in specified locale
* @param timeZoneName - name of the timezone to compare
* @param locale - locale to test against english
* @return empty string when passed, descriptive error message in other cases
*/
private static String testTZ(String timeZoneName, Locale locale) {
    StringBuffer timeZoneResult = new StringBuffer("");
    TimeZone tz = TimeZone.getTimeZone(timeZoneName);
    sdfEn.setTimeZone(tz);
    sdfEnShort.setTimeZone(tz);
    sdfLoc.setTimeZone(tz);
    sdfLocShort.setTimeZone(tz);

    String en, enShort, loc, locShort;
    en = sdfEn.format(date);
    enShort = sdfEnShort.format(date);
    loc = sdfLoc.format(date);
    locShort = sdfLocShort.format(date);

    String displayLanguage = locale.getDisplayLanguage();
    String displayCountry = locale.getDisplayCountry();

    if (loc.equals(en)) {
        timeZoneResult.append("[");
        timeZoneResult.append(displayLanguage);
        if (!"".equals(displayCountry)) {
            timeZoneResult.append(" ");
            timeZoneResult.append(displayCountry);
        }
        timeZoneResult.append("] timezone \"");
        timeZoneResult.append(timeZoneName);
        timeZoneResult.append("\" long name \"" + en);
        timeZoneResult.append("\" not localized!\n");
    }

    if (!locShort.equals(enShort)) {
        timeZoneResult.append("[");
        timeZoneResult.append(displayLanguage);
        if (!"".equals(displayCountry)) {
            timeZoneResult.append(" ");
            timeZoneResult.append(displayCountry);
        }
        timeZoneResult.append("] timezone \"");
        timeZoneResult.append(timeZoneName);
        timeZoneResult.append("\" short name \"" + enShort);
        timeZoneResult.append("\" is localized \"");
        timeZoneResult.append(locShort);
        timeZoneResult.append("\"!\n");
    }
    return timeZoneResult.toString();
}
 
Example 18
Source File: LocaleTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
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);
    }
}
 
Example 19
Source File: HongKong.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static void checkCountry(Locale country, String expected) {
    String actual = country.getDisplayCountry();
    if (!expected.equals(actual)) {
        throw new RuntimeException();
    }
}
 
Example 20
Source File: LocaleTest.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
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);
    }
}