Java Code Examples for java.util.Locale.getDisplayLanguage()

The following are Jave code examples for showing how to use getDisplayLanguage() of the java.util.Locale class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: markor   File: LanguagePreferenceCompat.java   View Source Code Vote up 6 votes
private String summarizeLocale(final Locale locale, final String localeAndroidCode) {
    String country = locale.getDisplayCountry(locale);
    String language = locale.getDisplayLanguage(locale);
    String ret = locale.getDisplayLanguage(Locale.ENGLISH)
            + " (" + language.substring(0, 1).toUpperCase(Locale.getDefault()) + language.substring(1)
            + ((!country.isEmpty() && !country.toLowerCase(Locale.getDefault()).equals(language.toLowerCase(Locale.getDefault()))) ? (", " + country) : "")
            + ")";

    if (localeAndroidCode.equals("zh-rCN")) {
        ret = ret.substring(0, ret.indexOf(" ") + 1) + "Simplified" + ret.substring(ret.indexOf(" "));
    } else if (localeAndroidCode.equals("zh-rTW")) {
        ret = ret.substring(0, ret.indexOf(" ") + 1) + "Traditional" + ret.substring(ret.indexOf(" "));
    }

    return ret;
}
 
Example 2
Project: MovieGuide   File: MovieActivity.java   View Source Code Vote up 6 votes
/**
 * Populates language in screen.
 * @param container MovieData
 */
private void PopulateDetailsLanguage(final MovieData container) {
    if (container.getOriginalLanguage() != null) {
        String name = "";
        Locale[] locales = Locale.getAvailableLocales();
        for (Locale l : locales) {
            if (l.getLanguage().equals(container.getOriginalLanguage())) {
                name = l.getDisplayLanguage();
            }
        }
        if(name.isEmpty()) {
            textLanguage.setText(container.getOriginalLanguage());
        }
        else {
            textLanguage.setText(name);
        }
        textLanguage.setVisibility(View.VISIBLE);
    }
    else {
        textLanguage.setVisibility(View.GONE);
    }
}
 
Example 3
Project: jdk8u-jdk   File: Bug6275682.java   View Source Code Vote up 6 votes
public static void main (String[] args) throws Exception {
    Locale es = new Locale ("es");
    String[] isoLangs = es.getISOLanguages ();
    String error = "";

    for (int i = 0; i < isoLangs.length; i++) {
        Locale current = new Locale (isoLangs[i]);
        String localeString = current.getDisplayLanguage (es);
        String startLetter = localeString.substring (0,1);
        if (!startLetter.toLowerCase (es).equals (startLetter)){
            error = error + "\n\t"+ isoLangs[i] + " " + localeString;
        }
    }

    if (error.length () > 0){
        throw new Exception ("\nFollowing language names starts with upper-case letter: "
                + error + "\nLower-case expected!");
    }

}
 
Example 4
Project: openjdk-jdk10   File: Bug6275682.java   View Source Code Vote up 6 votes
public static void main (String[] args) throws Exception {
    Locale es = new Locale ("es");
    String[] isoLangs = es.getISOLanguages ();
    String error = "";

    for (int i = 0; i < isoLangs.length; i++) {
        Locale current = new Locale (isoLangs[i]);
        String localeString = current.getDisplayLanguage (es);
        String startLetter = localeString.substring (0,1);
        if (!startLetter.toLowerCase (es).equals (startLetter)){
            error = error + "\n\t"+ isoLangs[i] + " " + localeString;
        }
    }

    if (error.length () > 0){
        throw new Exception ("\nFollowing language names starts with upper-case letter: "
                + error + "\nLower-case expected!");
    }

}
 
Example 5
Project: sstore-soft   File: Collation.java   View Source Code Vote up 5 votes
public void setCollationAsLocale() {

        Locale locale   = Locale.getDefault();
        String language = locale.getDisplayLanguage(Locale.ENGLISH);

        try {
            setCollation(language);
        } catch (HsqlException e) {}
    }
 
Example 6
Project: oscm   File: ApplicationBean.java   View Source Code Vote up 5 votes
public List<SelectItem> getAvailableLanguageItems() {
    List<SelectItem> availableLanguageItems = new ArrayList<SelectItem>();
    for (String isoCode : getActiveLocales()) {
        SelectItem selectItem = new SelectItem();
        Locale languageLocale = new Locale(isoCode);
        String translatedLocale = languageLocale.getDisplayLanguage(ui
                .getViewLocale());
        selectItem.setLabel(translatedLocale);
        selectItem.setValue(isoCode);
        availableLanguageItems.add(selectItem);
    }
    return availableLanguageItems;
}
 
Example 7
Project: oscm   File: SupportedLanguageAssembler.java   View Source Code Vote up 5 votes
private static void fillPOLanguage(POSupportedLanguage poLanguage,
        SupportedLanguage language, Locale currentUserLocale) {
    poLanguage.setKey(language.getKey());
    poLanguage.setLanguageISOCode(language.getLanguageISOCode());
    poLanguage.setActive(language.getActiveStatus());
    poLanguage.setDefaultLanguageStatus(language.getDefaultStatus());

    Locale locale = new Locale(language.getLanguageISOCode());
    String languageName = locale.getDisplayLanguage(currentUserLocale);
    poLanguage.setLanguageName(languageName);
}
 
Example 8
Project: s-store   File: Collation.java   View Source Code Vote up 5 votes
public void setCollationAsLocale() {

        Locale locale   = Locale.getDefault();
        String language = locale.getDisplayLanguage(Locale.ENGLISH);

        try {
            setCollation(language);
        } catch (HsqlException e) {}
    }
 
Example 9
Project: Equella   File: MultiEditBox.java   View Source Code Vote up 5 votes
@Override
protected void prepareModel(RenderContext info)
{
	super.prepareModel(info);
	final MultiEditBoxState state = getState(info);
	Map<String, HtmlValueState> map = new LinkedHashMap<String, HtmlValueState>();

	TreeSet<Locale> languages = new TreeSet<Locale>(localeComparator);
	languages.addAll(getContributeLocales());
	languages.addAll(getBundleLocales(info));

	for( Locale locale : languages )
	{
		String id = locale.toString();
		HtmlValueState valState = langMap.getValueState(info, id);

		// Build format into: Language [(country)] where country
		String displayString = Constants.BLANK;

		String displayLanguage = locale.getDisplayLanguage();
		String displayCountry = locale.getCountry();
		displayString = !Check.isEmpty(displayCountry) ? MessageFormat.format(
			"{0} ({1})", displayLanguage, displayCountry) : displayLanguage; //$NON-NLS-1$

		valState.setLabel(new TextLabel(displayString));
		map.put(id, valState);
	}
	state.setSize(size);
	state.setLocaleMap(map);
}
 
Example 10
Project: dev-courses   File: Collation.java   View Source Code Vote up 5 votes
public void setCollationAsLocale() {

        Locale locale   = Locale.getDefault();
        String language = locale.getDisplayLanguage(Locale.ENGLISH);

        try {
            setCollation(language, false);
        } catch (HsqlException e) {}
    }
 
Example 11
Project: parabuild-ci   File: Collation.java   View Source Code Vote up 5 votes
public void setCollationAsLocale() {

        Locale locale   = Locale.getDefault();
        String language = locale.getDisplayLanguage(Locale.ENGLISH);

        try {
            setCollation(language);
        } catch (HsqlException e) {}
    }
 
Example 12
Project: parabuild-ci   File: Collation.java   View Source Code Vote up 5 votes
public void setCollationAsLocale() {

        Locale locale   = Locale.getDefault();
        String language = locale.getDisplayLanguage(Locale.ENGLISH);

        try {
            setCollation(language);
        } catch (HsqlException e) {}
    }
 
Example 13
Project: parabuild-ci   File: Collation.java   View Source Code Vote up 5 votes
public void setCollationAsLocale() {

        Locale locale   = Locale.getDefault();
        String language = locale.getDisplayLanguage(Locale.ENGLISH);

        try {
            setCollation(language);
        } catch (HsqlException e) {}
    }
 
Example 14
Project: jdk8u-jdk   File: Bug4965260.java   View Source Code Vote up 5 votes
public static void main(String[] args) throws Exception {
    Locale reservedLocale = Locale.getDefault();
    try {
        Locale.setDefault(Locale.ENGLISH);
        if (locales2Test.length != expectedNames.length) {
            throw new Exception("\nData sizes does not match!\n");
        }

        StringBuffer message = new StringBuffer("");
        Locale dutch = new Locale("nl", "BE");
        String current;
        for (int i = 0; i < locales2Test.length; i++) {
            Locale locale = locales2Test[i];
            current = dutch.getDisplayLanguage(locale);
            if (!current.equals(expectedNames[i])) {
                message.append("[");
                message.append(locale.getDisplayLanguage());
                message.append("] ");
                message.append("Language name is ");
                message.append(current);
                message.append(" should be ");
                message.append(expectedNames[i]);
                message.append("\n");
            }
        }

        if (message.length() >0) {
            throw new Exception("\n" + message.toString());
        }
    } finally {
        // restore the reserved locale
        Locale.setDefault(reservedLocale);
    }
}
 
Example 15
Project: memetastic   File: LanguagePreferenceCompat.java   View Source Code Vote up 5 votes
private String summarizeLocale(Locale locale) {
    String country = locale.getDisplayCountry(locale);
    String language = locale.getDisplayLanguage(locale);
    return locale.getDisplayLanguage(Locale.ENGLISH)
            + " (" + language.substring(0, 1).toUpperCase(Locale.getDefault()) + language.substring(1)
            + ((!country.isEmpty() && !country.toLowerCase(Locale.getDefault()).equals(language.toLowerCase(Locale.getDefault()))) ? (", " + country) : "")
            + ")";
}
 
Example 16
Project: BiglyBT   File: LanguagePanel.java   View Source Code Vote up 5 votes
private String buildName(Locale locale) {
	StringBuilder sName = new StringBuilder();

	String sName1 = locale.getDisplayLanguage(locale);
	String sName2 = locale.getDisplayLanguage();
	sName.append(sName1);

	if (!sName1.equals(sName2)) {
		sName.append("/").append(sName2);
	}

	sName1 = locale.getDisplayCountry(locale);
	sName2 = locale.getDisplayCountry();
	if (sName1.length() > 0 || sName2.length() > 0) {
		sName.append(" (");
		if (sName1.length() > 0)
			sName.append(sName1);

		if (sName2.length() > 0 && !sName1.equals(sName2)) {
			sName.append("/").append(sName2);
		}

		sName1 = locale.getDisplayVariant(locale);
		sName2 = locale.getDisplayVariant();
		if (sName1.length() > 0 || sName2.length() > 0) {
			sName.append(", ");
			if (sName1.length() > 0)
				sName.append(sName1);

			if (sName2.length() > 0 && !sName1.equals(sName2)) {
				sName.append("/").append(sName2);
			}
		}

		sName.append(")");
	}

	return sName.toString();
}
 
Example 17
Project: openrouteservice   File: LocalizationManager.java   View Source Code Vote up 4 votes
private void loadLocalizations() throws Exception
{
	File classFile = new File(getClass().getProtectionDomain().getCodeSource().getLocation().getFile());
	String classPath = classFile.getAbsolutePath();
	String classesPath = classPath.substring(0, classPath.indexOf("classes") + "classes".length());
	Path localesPath = Paths.get(classesPath, "resources", "locales");

	String filePattern = "ors_(.*?).resources";
	Pattern pattern = Pattern.compile(filePattern);

	File[] files = new File(localesPath.toString()).listFiles();

	if (files == null)
		throw new Exception("Resources can not be found.");

	for (File file : files) {
		try
		{
			if (file.isFile()) {
				if (file.getName().matches(filePattern))
				{
					Matcher matcher = pattern.matcher(file.getName());
					if (matcher.find())
					{
						String langCode = matcher.group(1).toLowerCase();
						String[] langCountry = langCode.split("-");
						Locale locale = new Locale(langCountry[0], langCountry.length == 2 ? langCountry[1] : "");
						Language lang = new Language(langCode, locale.getDisplayLanguage(), locale.getDisplayName());
						LanguageResources langResources = new LanguageResources(lang);

						Config allConfig = ConfigFactory.parseFile(file);

						allConfig.entrySet().forEach(entry -> {
							langResources.addLocalString(entry.getKey(), StringUtility.trim(entry.getValue().render(), '\"'));
						});

						_langResources.put(langCode, langResources);
					}
				}
			}
		}
		catch(Exception ex)
		{
			LOGGER.error("Unable to load resources from file " + file.getAbsolutePath());				
		}
	}
}
 
Example 18
Project: jdk8u-jdk   File: LocaleTest.java   View Source Code Vote up 4 votes
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
Project: jdk8u-jdk   File: Bug4640234.java   View Source Code Vote up 4 votes
/**
* 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 20
Project: openjdk-jdk10   File: LocaleTest.java   View Source Code Vote up 4 votes
private void doTestDisplayNames(Locale inLocale, int compareIndex, boolean defaultIsFrench) {
    String language = Locale.getDefault().getLanguage();

    if (defaultIsFrench && !language.equals("fr")) {
        errln("Default locale should be French, but it's really " + language);
    } else if (!defaultIsFrench && !language.equals("en")) {
        errln("Default locale should be English, but it's really " + language);
    }

    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);
        }
    }
}