/** * Initializes the availableLocaleList. It is separate from availableLocaleList() * to avoid the synchronized block affecting normal use, yet synchronized and * lazy loading to avoid a static block affecting other methods in this class. */ private static synchronized void initAvailableLocaleList() { if(cAvailableLocaleList == null) { List list = Arrays.asList(Locale.getAvailableLocales()); cAvailableLocaleList = Collections.unmodifiableList(list); } }
public static String[] getLocaleList() { Locale[] locales = Locale.getAvailableLocales(); String[] strings = new String[locales.length]; for ( int i = 0; i < strings.length; i++ ) { strings[i] = locales[i].toString(); } Arrays.sort( strings ); return strings; } }
/** * Checks whether user specified language code is correct (is contained in available locales). * @param userSpecifiedLanguageCode user specified language code. * @return true if user specified language code is correct. */ private static boolean isValidLanguageCode(final String userSpecifiedLanguageCode) { boolean valid = false; final Locale[] locales = Locale.getAvailableLocales(); for (Locale locale : locales) { if (userSpecifiedLanguageCode.equals(locale.toString())) { valid = true; break; } } return valid; }
@Generates private Locale generateLocale() { return pickInstance(Locale.getAvailableLocales(), Locale.US); }
protected void setLocales() { Locale[] locale = Locale.getAvailableLocales(); dateLocale = new String[locale.length]; for ( int i = 0; i < locale.length; i++ ) { dateLocale[i] = locale[i].toString(); } if ( dateLocale != null ) { wDateLocale.setItems( dateLocale ); } }
protected void setLocales() { Locale[] locale = Locale.getAvailableLocales(); dateLocale = new String[locale.length]; for ( int i = 0; i < locale.length; i++ ) { dateLocale[i] = locale[i].toString(); } if ( dateLocale != null ) { wDateLocale.setItems( dateLocale ); } }
private static Locale getFixedLocale() { final String locale = Parameter.LOCALE.getValue(); if (locale != null) { for (final Locale l : Locale.getAvailableLocales()) { if (l.toString().equals(locale)) { return l; } } } return null; } }
@GET @ApiOperation(value = "Get supported locales") @Path("/locales") @Timed public LocalesResponse locales() { return LocalesResponse.create(Locale.getAvailableLocales()); }
if (pv instanceof AllView && AllView.DEFAULT_VIEW_NAME.equals(pv.name)) { for (Locale l : Locale.getAvailableLocales()) { if (name.equals(Messages._Hudson_ViewName().toString(l))) {
@Test // SPR-16651 public void testAvailableLocalesWithLocaleString() { for (Locale locale : Locale.getAvailableLocales()) { Locale parsedLocale = StringUtils.parseLocaleString(locale.toString()); if (parsedLocale == null) { assertEquals("", locale.getLanguage()); } else { assertEquals(parsedLocale.toString(), locale.toString()); } } }
@Test // SPR-16651 public void testAvailableLocalesWithLanguageTag() { for (Locale locale : Locale.getAvailableLocales()) { Locale parsedLocale = StringUtils.parseLocale(locale.toLanguageTag()); if (parsedLocale == null) { assertEquals("", locale.getLanguage()); } else { assertEquals(parsedLocale.toLanguageTag(), locale.toLanguageTag()); } } }
@Override public Locale getTestObject() { Locale[] availableLocales = Locale.getAvailableLocales(); Locale random = availableLocales[ new Random().nextInt( availableLocales.length ) ]; if ( Utils.isEmpty( random.toString() ) || random.toString().matches( "(\\w)*#.*" ) ) { // locales with '#', like 'sr_rs_#latn', are not restored properly return Locale.US; } else { return random; } }
@Test public void testTzParses() throws Exception { // Check that all Locales can parse the time formats we use for(final Locale locale : Locale.getAvailableLocales()) { final FastDateParser fdp= new FastDateParser("yyyy/MM/dd z", TimeZone.getDefault(), locale); for(final TimeZone tz : new TimeZone[]{NEW_YORK, REYKJAVIK, GMT}) { final Calendar cal= Calendar.getInstance(tz, locale); cal.clear(); cal.set(Calendar.YEAR, 2000); cal.set(Calendar.MONTH, 1); cal.set(Calendar.DAY_OF_MONTH, 10); final Date expected= cal.getTime(); final Date actual = fdp.parse("2000/02/10 "+tz.getDisplayName(locale)); assertEquals("tz:"+tz.getID()+" locale:"+locale.getDisplayName(), expected, actual); } } }
@Test public void testLocaleIndependence() { final Locale orig = Locale.getDefault(); final Locale[] locales = Locale.getAvailableLocales(); final String[][] data = { { "I", "i"}, { "i", "I"}, { "i", "\u0130"}, { "i", "\u0131"}, { "\u03A3", "\u03C2"}, { "\u03A3", "\u03C3"}, { "\u03C2", "\u03C3"}, }; try { for (int i = 0; i < data.length; i++) { for (final Locale locale : locales) { Locale.setDefault(locale); assertTrue("Test data corrupt: " + i, data[i][0].equalsIgnoreCase(data[i][1])); final boolean match = FilenameUtils.wildcardMatch(data[i][0], data[i][1], IOCase.INSENSITIVE); assertTrue(Locale.getDefault().toString() + ": " + i, match); } } } finally { Locale.setDefault(orig); } }
@Test // Check that all Locales can parse the formats we use public void testParses() throws Exception { for(final String format : new String[]{LONG_FORMAT, SHORT_FORMAT}) { for(final Locale locale : Locale.getAvailableLocales()) { for(final TimeZone tz : new TimeZone[]{NEW_YORK, REYKJAVIK, GMT}) { for(final int year : new int[]{2003, 1940, 1868, 1867, 1, -1, -1940}) { final Calendar cal= getEraStart(year, tz, locale); final Date centuryStart= cal.getTime(); cal.set(Calendar.MONTH, 1); cal.set(Calendar.DAY_OF_MONTH, 10); final Date in= cal.getTime(); final FastDateParser fdp= new FastDateParser(format, tz, locale, centuryStart); validateSdfFormatFdpParseEquality(format, locale, tz, fdp, in, year, centuryStart); } } } } }
private void testLocales(final String format, final boolean eraBC) throws Exception { final Calendar cal= Calendar.getInstance(GMT); cal.clear(); cal.set(2003, Calendar.FEBRUARY, 10); if (eraBC) { cal.set(Calendar.ERA, GregorianCalendar.BC); } for(final Locale locale : Locale.getAvailableLocales() ) { // ja_JP_JP cannot handle dates before 1868 properly if (eraBC && locale.equals(FastDateParser.JAPANESE_IMPERIAL)) { continue; } final SimpleDateFormat sdf = new SimpleDateFormat(format, locale); final DateParser fdf = getInstance(format, locale); try { checkParse(locale, cal, sdf, fdf); } catch(final ParseException ex) { fail("Locale "+locale+ " failed with "+format+" era "+(eraBC?"BC":"AD")+"\n" + trimMessage(ex.toString())); } } }
@Signature public static Memory getAvailableLocales(Environment env, Memory... args) { ArrayMemory r = new ArrayMemory(); for(Locale el : Locale.getAvailableLocales()) { r.add(new WrapLocale(env, el)); } return r.toConstant(); }
@Test public void testTimeZoneStrategyPattern() { for(final Locale locale : Locale.getAvailableLocales()) { final FastDateParser parser = new FastDateParser("z", TimeZone.getDefault(), locale); final String[][] zones = DateFormatSymbols.getInstance(locale).getZoneStrings(); for(final String[] zone : zones) { for(int t = 1; t<zone.length; ++t) { final String tzDisplay = zone[t]; if (tzDisplay == null) { break; } try { parser.parse(tzDisplay); } catch(final Exception ex) { fail("'" + tzDisplay + "'" + " Locale: '" + locale.getDisplayName() + "'" + " TimeZone: " + zone[0] + " offset: " + t + " defaultLocale: " + Locale.getDefault() + " defaultTimeZone: " + TimeZone.getDefault().getDisplayName() ); } } } } }
/** * Test availableLocaleSet() method. */ @Test public void testAvailableLocaleSet() { final Set<Locale> set = LocaleUtils.availableLocaleSet(); final Set<Locale> set2 = LocaleUtils.availableLocaleSet(); assertNotNull(set); assertSame(set, set2); assertUnmodifiableCollection(set); final Locale[] jdkLocaleArray = Locale.getAvailableLocales(); final List<Locale> jdkLocaleList = Arrays.asList(jdkLocaleArray); final Set<Locale> jdkLocaleSet = new HashSet<>(jdkLocaleList); assertEquals(jdkLocaleSet, set); }
/** * Test availableLocaleList() method. */ @Test public void testAvailableLocaleList() { final List<Locale> list = LocaleUtils.availableLocaleList(); final List<Locale> list2 = LocaleUtils.availableLocaleList(); assertNotNull(list); assertSame(list, list2); assertUnmodifiableCollection(list); final Locale[] jdkLocaleArray = Locale.getAvailableLocales(); final List<Locale> jdkLocaleList = Arrays.asList(jdkLocaleArray); assertEquals(jdkLocaleList, list); }