Java Code Examples for java.util.Locale#Builder
The following examples show how to use
java.util.Locale#Builder .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HostLocaleProviderAdapterImpl.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
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; }
Example 2
Source File: HostLocaleProviderAdapterImpl.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
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; }
Example 3
Source File: HostLocaleProviderAdapterImpl.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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; }
Example 4
Source File: TestAcceptLanguage.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Test public void bug56848() throws Exception { List<AcceptLanguage> actual = AcceptLanguage.parse(new StringReader("zh-hant-CN;q=0.5,zh-hans-TW;q=0.05")); Assert.assertEquals(2, actual.size()); Locale.Builder b = new Locale.Builder(); b.setLanguage("zh").setRegion("CN").setScript("hant"); Locale l1 = b.build(); b.clear().setLanguage("zh").setRegion("TW").setScript("hans"); Locale l2 = b.build(); Assert.assertEquals(l1, actual.get(0).getLocale()); Assert.assertEquals(Q0_500, actual.get(0).getQuality(), 0.0001); Assert.assertEquals(l2, actual.get(1).getLocale()); Assert.assertEquals(Q0_050, actual.get(1).getQuality(), 0.0001); }
Example 5
Source File: TCKChronology.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@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); }
Example 6
Source File: TCKChronology.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@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); }
Example 7
Source File: LocaleCategory.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
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); } }
Example 8
Source File: TCKChronology.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@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); }
Example 9
Source File: LocaleCategory.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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); } }
Example 10
Source File: TCKChronology.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * 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"); } }
Example 11
Source File: LocaleCategory.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
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); } }
Example 12
Source File: TCKChronology.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@Test(expectedExceptions=DateTimeException.class) public void test_lookupLocale() { Locale.Builder builder = new Locale.Builder().setLanguage("en").setRegion("CA"); builder.setUnicodeLocaleKeyword("ca", "xxx"); Locale locale = builder.build(); Chronology.ofLocale(locale); }
Example 13
Source File: TCKChronology.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * 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"); } }
Example 14
Source File: TCKChronology.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
@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); }
Example 15
Source File: HostLocaleProviderAdapterImpl.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
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; }
Example 16
Source File: TCKChronology.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Test(expectedExceptions=DateTimeException.class) public void test_lookupLocale() { Locale.Builder builder = new Locale.Builder().setLanguage("en").setRegion("CA"); builder.setUnicodeLocaleKeyword("ca", "xxx"); Locale locale = builder.build(); Chronology.ofLocale(locale); }
Example 17
Source File: TCKChronology.java From j2objc with Apache License 2.0 | 5 votes |
@Test(expected=DateTimeException.class) public void test_lookupLocale() { Locale.Builder builder = new Locale.Builder().setLanguage("en").setRegion("CA"); builder.setUnicodeLocaleKeyword("ca", "xxx"); Locale locale = builder.build(); Chronology.ofLocale(locale); }
Example 18
Source File: TCKChronology.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
@Test(expectedExceptions=DateTimeException.class) public void test_lookupLocale() { Locale.Builder builder = new Locale.Builder().setLanguage("en").setRegion("CA"); builder.setUnicodeLocaleKeyword("ca", "xxx"); Locale locale = builder.build(); Chronology.ofLocale(locale); }
Example 19
Source File: HostLocaleProviderAdapterImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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; }
Example 20
Source File: LocaleTest.java From j2objc with Apache License 2.0 | 4 votes |
public void test_toString() { Locale.Builder b = new Locale.Builder(); // Empty builder. Locale l = b.build(); assertEquals("", l.toString()); // Only language. b = new Locale.Builder(); b.setLanguage("en"); assertEquals("en", b.build().toString()); // Only region b = new Locale.Builder(); b.setRegion("US"); assertEquals("_US", b.build().toString()); // Language & Region b = new Locale.Builder(); b.setLanguage("en").setRegion("US"); assertEquals("en_US", b.build().toString()); // Language & Script b = new Locale.Builder(); b.setLanguage("en").setScript("Latn"); assertEquals("en__#Latn", b.build().toString()); // Language & Variant b = new Locale.Builder(); b.setLanguage("en").setVariant("foooo"); assertEquals("en__foooo", b.build().toString()); // Language / script & country b = new Locale.Builder(); b.setLanguage("en").setScript("Latn").setRegion("US"); assertEquals("en_US_#Latn", b.build().toString()); // Language / script & variant b = new Locale.Builder(); b.setLanguage("en").setScript("Latn").setVariant("foooo"); assertEquals("en__foooo_#Latn", b.build().toString()); // Language / script / country / variant. b = new Locale.Builder(); b.setLanguage("en").setScript("Latn").setVariant("foooo").setRegion("US"); assertEquals("en_US_foooo_#Latn", b.build().toString()); // Language / extension b = new Locale.Builder(); b.setLanguage("en").setExtension('x', "fooo-baar"); assertEquals("en__#x-fooo-baar", b.build().toString()); }