本文整理汇总了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;
}
示例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);
}
}
示例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!");
}
}
示例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) {}
}
示例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;
}
示例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);
}
示例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);
}
示例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) {}
}
示例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);
}
}
示例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) : "")
+ ")";
}
示例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();
}
示例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());
}
}
}
示例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);
}
}
示例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();
}
示例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);
}
}
}