use of android.icu.impl.ICUResourceBundle in project j2objc by google.
the class MeasureUnit method populateCache.
/**
* Populate the MeasureUnit cache with all types from the data.
* Population is done lazily, in response to MeasureUnit.getAvailable()
* or other API that expects to see all of the MeasureUnits.
*
* <p>At static initialization time the MeasureUnits cache is populated
* with public static instances (G_FORCE, METER_PER_SECOND_SQUARED, etc.) only.
* Adding of others is deferred until later to avoid circular static init
* dependencies with classes Currency and TimeUnit.
*
* <p>Synchronization: this function must be called from static synchronized methods only.
*
* @hide draft / provisional / internal are hidden on Android
*/
private static void populateCache() {
if (cacheIsPopulated) {
return;
}
cacheIsPopulated = true;
/* Schema:
*
* units{
* duration{
* day{
* one{"{0} ден"}
* other{"{0} дена"}
* }
*/
// Load the unit types. Use English, since we know that that is a superset.
ICUResourceBundle rb1 = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_UNIT_BASE_NAME, "en");
rb1.getAllItemsWithFallback("units", new MeasureUnitSink());
// Load the currencies
ICUResourceBundle rb2 = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, "currencyNumericCodes", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
rb2.getAllItemsWithFallback("codeMap", new CurrencyNumericCodeSink());
}
use of android.icu.impl.ICUResourceBundle in project j2objc by google.
the class LocaleData method getDelimiter.
/**
* Retrieves a delimiter string from the locale data.
*
* @param type The type of delimiter string desired. Currently,
* the valid choices are QUOTATION_START, QUOTATION_END,
* ALT_QUOTATION_START, or ALT_QUOTATION_END.
* @return The desired delimiter string.
*/
public String getDelimiter(int type) {
ICUResourceBundle delimitersBundle = (ICUResourceBundle) bundle.get("delimiters");
// Only some of the quotation marks may be here. So we make sure that we do a multilevel fallback.
ICUResourceBundle stringBundle = delimitersBundle.getWithFallback(DELIMITER_TYPES[type]);
if (noSubstitute && !bundle.isRoot() && stringBundle.isRoot()) {
return null;
}
return stringBundle.getString();
}
use of android.icu.impl.ICUResourceBundle in project j2objc by google.
the class LocaleData method getLocaleSeparator.
/**
* Returns LocaleDisplaySeparator for this locale.
* @return locale display separator as a char.
*/
public String getLocaleSeparator() {
String sub0 = "{0}";
String sub1 = "{1}";
ICUResourceBundle locDispBundle = (ICUResourceBundle) langBundle.get(LOCALE_DISPLAY_PATTERN);
String localeSeparator = locDispBundle.getStringWithFallback(SEPARATOR);
int index0 = localeSeparator.indexOf(sub0);
int index1 = localeSeparator.indexOf(sub1);
if (index0 >= 0 && index1 >= 0 && index0 <= index1) {
return localeSeparator.substring(index0 + sub0.length(), index1);
}
return localeSeparator;
}
use of android.icu.impl.ICUResourceBundle in project j2objc by google.
the class LocaleData method getLocaleDisplayPattern.
/**
* Returns LocaleDisplayPattern for this locale, e.g., {0}({1})
* @return locale display pattern as a String.
*/
public String getLocaleDisplayPattern() {
ICUResourceBundle locDispBundle = (ICUResourceBundle) langBundle.get(LOCALE_DISPLAY_PATTERN);
String localeDisplayPattern = locDispBundle.getStringWithFallback(PATTERN);
return localeDisplayPattern;
}
use of android.icu.impl.ICUResourceBundle in project j2objc by google.
the class MyNumberFormat method Test4122840.
/**
* Locale data should use generic currency symbol
*
* 1) Make sure that all currency formats use the generic currency symbol.
* 2) Make sure we get the same results using the generic symbol or a
* hard-coded one.
*/
@Test
public void Test4122840() {
Locale[] locales = NumberFormat.getAvailableLocales();
for (int i = 0; i < locales.length; i++) {
ICUResourceBundle rb = (ICUResourceBundle) ICUResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, locales[i]);
//
// Get the currency pattern for this locale. We have to fish it
// out of the ResourceBundle directly, since DecimalFormat.toPattern
// will return the localized symbol, not \00a4
//
String pattern = rb.getStringWithFallback("NumberElements/latn/patterns/currencyFormat");
if (pattern.indexOf('\u00A4') == -1) {
// 'x' not "x" -- workaround bug in IBM JDK 1.4.1
errln("Currency format for " + locales[i] + " does not contain generic currency symbol:" + pattern);
}
// Create a DecimalFormat using the pattern we got and format a number
DecimalFormatSymbols symbols = new DecimalFormatSymbols(locales[i]);
DecimalFormat fmt1 = new DecimalFormat(pattern, symbols);
String result1 = fmt1.format(1.111);
//
// Now substitute in the locale's currency symbol and create another
// pattern. Replace the decimal separator with the monetary separator.
//
// char decSep = symbols.getDecimalSeparator(); //The variable is never used
char monSep = symbols.getMonetaryDecimalSeparator();
StringBuffer buf = new StringBuffer(pattern);
for (int j = 0; j < buf.length(); j++) {
if (buf.charAt(j) == '\u00a4') {
String cur = "'" + symbols.getCurrencySymbol() + "'";
buf.replace(j, j + 1, cur);
j += cur.length() - 1;
}
}
symbols.setDecimalSeparator(monSep);
DecimalFormat fmt2 = new DecimalFormat(buf.toString(), symbols);
// Actual width of decimal fractions and rounding option are inherited
// from the currency, not the pattern itself. So we need to force
// maximum/minimumFractionDigits and rounding option for the second
// DecimalForamt instance. The fix for ticket#7282 requires this test
// code change to make it work properly.
fmt2.setMaximumFractionDigits(fmt1.getMaximumFractionDigits());
fmt2.setMinimumFractionDigits(fmt1.getMinimumFractionDigits());
fmt2.setRoundingIncrement(fmt1.getRoundingIncrement());
String result2 = fmt2.format(1.111);
// NOTE: en_IN is a special case (ChoiceFormat currency display name)
if (!result1.equals(result2) && !locales[i].toString().equals("en_IN")) {
errln("Results for " + locales[i] + " differ: " + result1 + " vs " + result2);
}
}
}
Aggregations