当前位置: 首页>>代码示例>>Java>>正文


Java Locale.getDisplayLanguage方法代码示例

本文整理汇总了Java中java.util.Locale.getDisplayLanguage方法的典型用法代码示例。如果您正苦于以下问题:Java Locale.getDisplayLanguage方法的具体用法?Java Locale.getDisplayLanguage怎么用?Java Locale.getDisplayLanguage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Locale的用法示例。


在下文中一共展示了Locale.getDisplayLanguage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: summarizeLocale

import java.util.Locale; //导入方法依赖的package包/类
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;
}
 
开发者ID:gsantner,项目名称:markor,代码行数:17,代码来源:LanguagePreferenceCompat.java

示例2: PopulateDetailsLanguage

import java.util.Locale; //导入方法依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:an-garcia,项目名称:MovieGuide,代码行数:26,代码来源:MovieActivity.java

示例3: main

import java.util.Locale; //导入方法依赖的package包/类
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!");
    }

}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:Bug6275682.java

示例4: setCollationAsLocale

import java.util.Locale; //导入方法依赖的package包/类
public void setCollationAsLocale() {

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

        try {
            setCollation(language);
        } catch (HsqlException e) {}
    }
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:10,代码来源:Collation.java

示例5: getAvailableLanguageItems

import java.util.Locale; //导入方法依赖的package包/类
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;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:14,代码来源:ApplicationBean.java

示例6: fillPOLanguage

import java.util.Locale; //导入方法依赖的package包/类
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);
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:12,代码来源:SupportedLanguageAssembler.java

示例7: prepareModel

import java.util.Locale; //导入方法依赖的package包/类
@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);
}
 
开发者ID:equella,项目名称:Equella,代码行数:31,代码来源:MultiEditBox.java

示例8: setCollationAsLocale

import java.util.Locale; //导入方法依赖的package包/类
public void setCollationAsLocale() {

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

        try {
            setCollation(language, false);
        } catch (HsqlException e) {}
    }
 
开发者ID:Julien35,项目名称:dev-courses,代码行数:10,代码来源:Collation.java

示例9: main

import java.util.Locale; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:35,代码来源:Bug4965260.java

示例10: summarizeLocale

import java.util.Locale; //导入方法依赖的package包/类
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) : "")
            + ")";
}
 
开发者ID:gsantner,项目名称:memetastic,代码行数:9,代码来源:LanguagePreferenceCompat.java

示例11: buildName

import java.util.Locale; //导入方法依赖的package包/类
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();
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:40,代码来源:LanguagePanel.java

示例12: loadLocalizations

import java.util.Locale; //导入方法依赖的package包/类
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());				
		}
	}
}
 
开发者ID:GIScience,项目名称:openrouteservice,代码行数:48,代码来源:LocalizationManager.java

示例13: doTestDisplayNames

import java.util.Locale; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:68,代码来源:LocaleTest.java

示例14: testTZ

import java.util.Locale; //导入方法依赖的package包/类
/**
* 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();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:53,代码来源:Bug4640234.java

示例15: doTestDisplayNames

import java.util.Locale; //导入方法依赖的package包/类
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);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:82,代码来源:LocaleTest.java


注:本文中的java.util.Locale.getDisplayLanguage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。