/** * Gets the default locales list * @return a list of ULocale instances for the default locale */ protected static List<ULocale> getDefaultLocaleList(){ GlobalizationPreferences prefs = new GlobalizationPreferences(); return prefs.getLocales(); }
/** * Convenience routine for setting the language/locale priority * list from a single locale/language. * * @see #setLocales(List locales) * @param uLocale single locale * @return this, for chaining * @draft ICU 3.6 * @provisional This API might change or be removed in a future release. */ public GlobalizationPreferences setLocale(ULocale uLocale) { if (isFrozen()) { throw new UnsupportedOperationException("Attempt to modify immutable object"); } return setLocales(new ULocale[]{uLocale}); }
/** * This function can be overridden by subclasses to use different heuristics. * <b>It MUST return a 'safe' value, * one whose modification will not affect this object.</b> * * @draft ICU 3.6 * @provisional This API might change or be removed in a future release. */ protected Calendar guessCalendar() { ULocale calLocale = getAvailableLocale(TYPE_CALENDAR); if (calLocale == null) { calLocale = ULocale.US; } return Calendar.getInstance(getTimeZone(), calLocale); }
private ULocale getAvailableLocale(int type) { List<ULocale> locs = getLocales(); ULocale result = null; for (int i = 0; i < locs.size(); i++) { ULocale l = locs.get(i); if (isAvailableLocale(l, type)) { result = l; break; } } return result; }
GlobalizationPreferences prefs = new GlobalizationPreferences(); prefs.setLocales(ulocales.toArray(new ULocale[ulocales.size()])); return prefs.getLocales();
String result; for (ULocale locale : getLocales()) { result = locale.getCountry(); if (result.length() != 0) { ULocale firstLocale = getLocale(0); String language = firstLocale.getLanguage(); String script = firstLocale.getScript();
UResourceBundle candidate = null; String actualLocaleName = null; List<ULocale> fallbacks = getLocales(); for (int i = 0; i < fallbacks.size(); i++) { String localeName = (fallbacks.get(i)).toString();
/** * This function can be overridden by subclasses to use different heuristics. * <b>It MUST return a 'safe' value, * one whose modification will not affect this object.</b> * * @param dateStyle * @param timeStyle * @draft ICU 3.6 * @provisional This API might change or be removed in a future release. */ protected DateFormat guessDateFormat(int dateStyle, int timeStyle) { DateFormat result; ULocale dfLocale = getAvailableLocale(TYPE_DATEFORMAT); if (dfLocale == null) { dfLocale = ULocale.ROOT; } if (timeStyle == DF_NONE) { result = DateFormat.getDateInstance(getCalendar(), dateStyle, dfLocale); } else if (dateStyle == DF_NONE) { result = DateFormat.getTimeInstance(getCalendar(), timeStyle, dfLocale); } else { result = DateFormat.getDateTimeInstance(getCalendar(), dateStyle, timeStyle, dfLocale); } return result; }
ULocale nfLocale = getAvailableLocale(TYPE_NUMBERFORMAT); if (nfLocale == null) { nfLocale = ULocale.ROOT; case NF_CURRENCY: result = NumberFormat.getCurrencyInstance(nfLocale); result.setCurrency(getCurrency()); break; default:
String timezoneString = territory_tzid_hack_map.get(getTerritory()); if (timezoneString == null) { String[] attempt = TimeZone.getAvailableIDs(getTerritory()); if (attempt.length == 0) { timezoneString = "Etc/GMT"; // gotta do something
/** * This function can be overridden by subclasses to use different heuristics. * <b>It MUST return a 'safe' value, * one whose modification will not affect this object.</b> * * @draft ICU 3.6 * @provisional This API might change or be removed in a future release. */ protected Collator guessCollator() { ULocale collLocale = getAvailableLocale(TYPE_COLLATOR); if (collLocale == null) { collLocale = ULocale.ROOT; } return Collator.getInstance(collLocale); }
/** * Convenience function to get a ResourceBundle instance using * the specified base name based on the language/locale priority list * stored in this object. * * @param baseName the base name of the resource bundle, a fully qualified * class name * @return a resource bundle for the given base name and locale based on the * language/locale priority list stored in this object * @draft ICU 3.6 * @provisional This API might change or be removed in a future release. */ public ResourceBundle getResourceBundle(String baseName) { return getResourceBundle(baseName, null); }
if (locales == null) return getDefaultLocaleList(); GlobalizationPreferences prefs = new GlobalizationPreferences(); prefs.setLocales(ulocales.toArray(new ULocale[ulocales.size()])); return prefs.getLocales();
for (ULocale locale : getLocales()) { if (!isAvailableLocale(locale, TYPE_GENERIC)) { continue;
/** * This function can be overridden by subclasses to use different heuristics * * @draft ICU 3.6 * @provisional This API might change or be removed in a future release. */ protected Currency guessCurrency() { return Currency.getInstance(new ULocale("und-" + getTerritory())); }
ULocale brkLocale = getAvailableLocale(TYPE_BREAKITERATOR); if (brkLocale == null) { brkLocale = ULocale.ROOT;
/** * Gets the default locales list * * @return */ protected static List<ULocale> getDefaultLocaleList() { GlobalizationPreferences prefs = new GlobalizationPreferences(); return prefs.getLocales(); }
/** * Convenience routine for setting the language/locale priority * list from an array. * * @see #setLocales(List locales) * @param uLocales list of locales in an array * @return this, for chaining * @draft ICU 3.6 * @provisional This API might change or be removed in a future release. */ public GlobalizationPreferences setLocales(ULocale[] uLocales) { if (isFrozen()) { throw new UnsupportedOperationException("Attempt to modify immutable object"); } return setLocales(Arrays.asList(uLocales)); }
/** * Convenience routine for setting the locale priority list from * an Accept-Language string. * @see #setLocales(List locales) * @param acceptLanguageString Accept-Language list, as defined by * Section 14.4 of the RFC 2616 (HTTP 1.1) * @return this, for chaining * @draft ICU 3.6 * @provisional This API might change or be removed in a future release. */ public GlobalizationPreferences setLocales(String acceptLanguageString) { if (isFrozen()) { throw new UnsupportedOperationException("Attempt to modify immutable object"); } ULocale[] acceptLocales = null; try { acceptLocales = ULocale.parseAcceptLanguage(acceptLanguageString, true); } catch (ParseException pe) { //TODO: revisit after 3.8 throw new IllegalArgumentException("Invalid Accept-Language string"); } return setLocales(acceptLocales); }