本文整理匯總了Java中java.util.Locale.getDisplayVariant方法的典型用法代碼示例。如果您正苦於以下問題:Java Locale.getDisplayVariant方法的具體用法?Java Locale.getDisplayVariant怎麽用?Java Locale.getDisplayVariant使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Locale
的用法示例。
在下文中一共展示了Locale.getDisplayVariant方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
示例2: 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);
}
}
示例3: 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);
}
}
}