本文整理汇总了Java中java.util.Locale.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java Locale.Builder方法的具体用法?Java Locale.Builder怎么用?Java Locale.Builder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Locale
的用法示例。
在下文中一共展示了Locale.Builder方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCalendarLocale
import java.util.Locale; //导入方法依赖的package包/类
private static Locale getCalendarLocale(Locale locale) {
int calid = getCalendarID(locale.toLanguageTag());
if (calid > 0 && calid < calIDToLDML.length) {
Locale.Builder lb = new Locale.Builder();
String[] caltype = calIDToLDML[calid].split("_");
if (caltype.length > 1) {
lb.setLocale(Locale.forLanguageTag(caltype[1]));
} else {
lb.setLocale(locale);
}
lb.setUnicodeLocaleKeyword("ca", caltype[0]);
return lb.build();
}
return locale;
}
示例2: createLocale
import java.util.Locale; //导入方法依赖的package包/类
private static Locale createLocale(@NonNull String language, @Nullable String region, @Nullable String script) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Locale.Builder localeBuilder = new Locale.Builder();
localeBuilder.setLanguage(language);
if (region != null) {
localeBuilder.setRegion(region);
}
if (script != null) {
localeBuilder.setScript(script);
}
return localeBuilder.build();
} else {
if (region == null) {
return new Locale(language);
} else if (script == null) {
return new Locale(language, region);
} else {
return new Locale(language, region, script);
}
}
}
示例3: getCalendarLocale
import java.util.Locale; //导入方法依赖的package包/类
private static Locale getCalendarLocale(Locale locale) {
int calid = getCalendarID(stripVariantAndExtensions(locale).toLanguageTag());
if (calid > 0 && calid < calIDToLDML.length) {
Locale.Builder lb = new Locale.Builder();
String[] caltype = calIDToLDML[calid].split("_");
if (caltype.length > 1) {
lb.setLocale(Locale.forLanguageTag(caltype[1]));
} else {
lb.setLocale(locale);
}
lb.setUnicodeLocaleKeyword("ca", caltype[0]);
return lb.build();
}
return locale;
}
示例4: getNumberLocale
import java.util.Locale; //导入方法依赖的package包/类
private static Locale getNumberLocale(Locale src) {
if (JRELocaleConstants.TH_TH.equals(src)) {
if (isNativeDigit("th-TH")) {
Locale.Builder lb = new Locale.Builder().setLocale(src);
lb.setUnicodeLocaleKeyword("nu", "thai");
return lb.build();
}
}
return src;
}
示例5: test_lookupLocale
import java.util.Locale; //导入方法依赖的package包/类
@Test(dataProvider = "calendarsystemtype")
public void test_lookupLocale(Chronology chrono, String calendarType) {
Locale.Builder builder = new Locale.Builder().setLanguage("en").setRegion("CA");
builder.setUnicodeLocaleKeyword("ca", calendarType);
Locale locale = builder.build();
assertEquals(Chronology.ofLocale(locale), chrono);
}
示例6: test_ofLocaleByType
import java.util.Locale; //导入方法依赖的package包/类
/**
* Test lookup by calendarType of each chronology.
* Verify that the calendar can be found by {@link java.time.chrono.Chronology#ofLocale}.
*/
@Test
public void test_ofLocaleByType() {
// Test that all available chronologies can be successfully found using ofLocale
Set<Chronology> chronos = Chronology.getAvailableChronologies();
for (Chronology chrono : chronos) {
Locale.Builder builder = new Locale.Builder().setLanguage("en").setRegion("CA");
builder.setUnicodeLocaleKeyword("ca", chrono.getCalendarType());
Locale locale = builder.build();
assertEquals(Chronology.ofLocale(locale), chrono, "Lookup by type");
}
}
示例7: test_HijrahTypeViaLocale
import java.util.Locale; //导入方法依赖的package包/类
@Test(dataProvider= "HijrahTypeNames")
public void test_HijrahTypeViaLocale(String calendarId, String calendarType) {
Locale.Builder builder = new Locale.Builder();
builder.setLanguage("en").setRegion("US");
builder.setUnicodeLocaleKeyword("ca", calendarType);
Locale locale = builder.build();
Chronology chrono = Chronology.ofLocale(locale);
System.out.printf(" Locale language tag: %s, Chronology ID: %s, type: %s%n",
locale.toLanguageTag(), chrono, chrono.getCalendarType());
Chronology expected = Chronology.of(calendarId);
assertEquals(chrono, expected, "Expected chronology not found");
}
示例8: main
import java.util.Locale; //导入方法依赖的package包/类
public static void main(String[] args) {
Locale reservedLocale = Locale.getDefault();
try {
Locale.Builder builder = new Locale.Builder();
base = builder.setLanguage(System.getProperty("user.language", ""))
.setScript(System.getProperty("user.script", ""))
.setRegion(System.getProperty("user.country", ""))
.setVariant(System.getProperty("user.variant", "")).build();
disp = builder.setLanguage(
System.getProperty("user.language.display",
Locale.getDefault().getLanguage()))
.setScript(System.getProperty("user.script.display",
Locale.getDefault().getScript()))
.setRegion(System.getProperty("user.country.display",
Locale.getDefault().getCountry()))
.setVariant(System.getProperty("user.variant.display",
Locale.getDefault().getVariant())).build();
fmt = builder.setLanguage(System.getProperty("user.language.format",
Locale.getDefault().getLanguage()))
.setScript(System.getProperty("user.script.format",
Locale.getDefault().getScript()))
.setRegion(System.getProperty("user.country.format",
Locale.getDefault().getCountry()))
.setVariant(System.getProperty("user.variant.format",
Locale.getDefault().getVariant())).build();
checkDefault();
testGetSetDefault();
testBug7079486();
} finally {
// restore the reserved locale
Locale.setDefault(reservedLocale);
}
}
示例9: main
import java.util.Locale; //导入方法依赖的package包/类
public static void main(String[] args) {
Locale reservedLocale = Locale.getDefault();
if (TestUtils.hasSpecialVariant(reservedLocale)) {
System.out.println("Skipping this test because locale is " + reservedLocale);
return;
}
try {
Locale.Builder builder = new Locale.Builder();
base = builder.setLanguage(System.getProperty("user.language", ""))
.setScript(System.getProperty("user.script", ""))
.setRegion(System.getProperty("user.country", ""))
.setVariant(System.getProperty("user.variant", "")).build();
disp = builder.setLanguage(
System.getProperty("user.language.display",
Locale.getDefault().getLanguage()))
.setScript(System.getProperty("user.script.display",
Locale.getDefault().getScript()))
.setRegion(System.getProperty("user.country.display",
Locale.getDefault().getCountry()))
.setVariant(System.getProperty("user.variant.display",
Locale.getDefault().getVariant())).build();
fmt = builder.setLanguage(System.getProperty("user.language.format",
Locale.getDefault().getLanguage()))
.setScript(System.getProperty("user.script.format",
Locale.getDefault().getScript()))
.setRegion(System.getProperty("user.country.format",
Locale.getDefault().getCountry()))
.setVariant(System.getProperty("user.variant.format",
Locale.getDefault().getVariant())).build();
checkDefault();
testGetSetDefault();
testBug7079486();
} finally {
// restore the reserved locale
Locale.setDefault(reservedLocale);
}
}