use of libcore.icu.LocaleData in project j2objc by google.
the class LocaleDataTest method test_cs_CZ.
public void test_cs_CZ() throws Exception {
LocaleData l = LocaleData.get(new Locale("cs", "CZ"));
assertEquals("ledna", l.longMonthNames[0]);
assertEquals("led", l.shortMonthNames[0]);
assertEquals("1", l.tinyMonthNames[0]);
assertEquals("leden", l.longStandAloneMonthNames[0]);
assertEquals("led", l.shortStandAloneMonthNames[0]);
assertEquals("1", l.tinyStandAloneMonthNames[0]);
}
use of libcore.icu.LocaleData in project j2objc by google.
the class Currency method getSymbol.
/**
* Gets the symbol of this currency for the specified locale.
* For example, for the US Dollar, the symbol is "$" if the specified
* locale is the US, while for other locales it may be "US$". If no
* symbol can be determined, the ISO 4217 currency code is returned.
*
* @param locale the locale for which a display name for this currency is
* needed
* @return the symbol of this currency for the specified locale
* @exception NullPointerException if <code>locale</code> is null
*/
public String getSymbol(Locale locale) {
if (locale == null) {
throw new NullPointerException("locale == null");
}
// Check the locale first, in case the locale has the same currency.
LocaleData localeData = LocaleData.get(locale);
if (localeData.internationalCurrencySymbol.equals(currencyCode)) {
return localeData.currencySymbol;
}
// Try ICU, and fall back to the currency code if ICU has nothing.
String symbol = ICU.getCurrencySymbol(locale, currencyCode);
return symbol != null ? symbol : currencyCode;
}
use of libcore.icu.LocaleData in project j2objc by google.
the class NumberFormat method getInstance.
// =======================privates===============================
private static NumberFormat getInstance(Locale desiredLocale, int choice) {
// Check whether a provider can provide an implementation that's closer
// to the requested locale than what the Java runtime itself can provide.
/* J2ObjC: java.text.spi is not provided.
LocaleServiceProviderPool pool =
LocaleServiceProviderPool.getPool(NumberFormatProvider.class);
if (pool.hasProviders()) {
NumberFormat providersInstance = pool.getLocalizedObject(
NumberFormatGetter.INSTANCE,
desiredLocale,
choice);
if (providersInstance != null) {
return providersInstance;
}
}*/
/* try the cache first */
String[] numberPatterns = (String[]) cachedLocaleData.get(desiredLocale);
if (numberPatterns == null) {
/* cache miss */
LocaleData data = LocaleData.get(desiredLocale);
numberPatterns = new String[4];
numberPatterns[NUMBERSTYLE] = data.numberPattern;
numberPatterns[CURRENCYSTYLE] = data.currencyPattern;
numberPatterns[PERCENTSTYLE] = data.percentPattern;
numberPatterns[INTEGERSTYLE] = data.integerPattern;
/* update cache */
cachedLocaleData.put(desiredLocale, numberPatterns);
}
DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(desiredLocale);
int entry = (choice == INTEGERSTYLE) ? NUMBERSTYLE : choice;
DecimalFormat format = new DecimalFormat(numberPatterns[entry], symbols);
if (choice == INTEGERSTYLE) {
format.setMaximumFractionDigits(0);
format.setDecimalSeparatorAlwaysShown(false);
format.setParseIntegerOnly(true);
} else if (choice == CURRENCYSTYLE) {
adjustForCurrencyDefaultFractionDigits(format, symbols);
}
return format;
}
use of libcore.icu.LocaleData in project j2objc by google.
the class DateFormatSymbols method readObject.
// BEGIN Android-added: support reading non-Android serialized DFS.
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
stream.defaultReadObject();
if (serialVersionOnStream < 1) {
LocaleData localeData = LocaleData.get(locale);
initializeSupplementaryData(localeData);
}
serialVersionOnStream = currentSerialVersion;
}
use of libcore.icu.LocaleData in project j2objc by google.
the class DateFormatSymbols method initializeData.
// Android-changed: update comment to describe local modification.
/**
* Initializes this DateFormatSymbols with the locale data. This method uses
* a cached DateFormatSymbols instance for the given locale if available. If
* there's no cached one, this method populates this objects fields from an
* appropriate LocaleData object. Note: zoneStrings isn't initialized in this method.
*/
private void initializeData(Locale locale) {
SoftReference<DateFormatSymbols> ref = cachedInstances.get(locale);
DateFormatSymbols dfs;
// Android-changed: invert cache presence check to simplify code flow.
if (ref != null && (dfs = ref.get()) != null) {
copyMembers(dfs, this);
return;
}
// BEGIN Android-changed: Use ICU data and move cache handling to getCachedInstance().
locale = LocaleData.mapInvalidAndNullLocales(locale);
LocaleData localeData = LocaleData.get(locale);
this.locale = locale;
eras = localeData.eras;
months = localeData.longMonthNames;
shortMonths = localeData.shortMonthNames;
ampms = localeData.amPm;
localPatternChars = patternChars;
weekdays = localeData.longWeekdayNames;
shortWeekdays = localeData.shortWeekdayNames;
initializeSupplementaryData(localeData);
// END Android-changed: Use ICU data and move cache handling to getCachedInstance().
}
Aggregations