use of android.icu.impl.ICUResourceBundle in project j2objc by google.
the class ICUResourceBundleCollationTest method TestGetWithFallback.
@Test
public void TestGetWithFallback() {
/*
UResourceBundle bundle =(UResourceBundle) UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","te_IN");
String key = bundle.getStringWithFallback("Keys/collation");
if(!key.equals("COLLATION")){
errln("Did not get the expected result from getStringWithFallback method.");
}
String type = bundle.getStringWithFallback("Types/collation/direct");
if(!type.equals("DIRECT")){
errln("Did not get the expected result form getStringWithFallback method.");
}
*/
ICUResourceBundle bundle = null;
String key = null;
try {
bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_COLLATION_BASE_NAME, ULocale.canonicalize("de__PHONEBOOK"));
if (!bundle.getULocale().getName().equals("de")) {
errln("did not get the expected bundle");
}
key = bundle.getStringWithFallback("collations/collation/default");
if (!key.equals("phonebook")) {
errln("Did not get the expected result from getStringWithFallback method.");
}
} catch (MissingResourceException ex) {
logln("got the expected exception");
}
bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_COLLATION_BASE_NAME, "fr_FR");
key = bundle.getStringWithFallback("collations/default");
if (!key.equals("standard")) {
errln("Did not get the expected result from getStringWithFallback method.");
}
}
use of android.icu.impl.ICUResourceBundle in project j2objc by google.
the class DateTimeTextProvider method createStore.
private Object createStore(TemporalField field, Locale locale) {
Map<TextStyle, Map<Long, String>> styleMap = new HashMap<>();
if (field == ERA) {
for (TextStyle textStyle : TextStyle.values()) {
if (textStyle.isStandalone()) {
// Stand-alone isn't applicable to era names.
continue;
}
Map<String, Integer> displayNames = CalendarDataUtility.retrieveJavaTimeFieldValueNames("gregory", Calendar.ERA, textStyle.toCalendarStyle(), locale);
if (displayNames != null) {
Map<Long, String> map = new HashMap<>();
for (Entry<String, Integer> entry : displayNames.entrySet()) {
map.put((long) entry.getValue(), entry.getKey());
}
if (!map.isEmpty()) {
styleMap.put(textStyle, map);
}
}
}
return new LocaleStore(styleMap);
}
if (field == MONTH_OF_YEAR) {
for (TextStyle textStyle : TextStyle.values()) {
Map<String, Integer> displayNames = CalendarDataUtility.retrieveJavaTimeFieldValueNames("gregory", Calendar.MONTH, textStyle.toCalendarStyle(), locale);
Map<Long, String> map = new HashMap<>();
if (displayNames != null) {
for (Entry<String, Integer> entry : displayNames.entrySet()) {
map.put((long) (entry.getValue() + 1), entry.getKey());
}
} else {
// Get names one by one in that case.
for (int month = Calendar.JANUARY; month <= Calendar.DECEMBER; month++) {
String name;
name = CalendarDataUtility.retrieveJavaTimeFieldValueName("gregory", Calendar.MONTH, month, textStyle.toCalendarStyle(), locale);
if (name == null) {
break;
}
map.put((long) (month + 1), name);
}
}
if (!map.isEmpty()) {
styleMap.put(textStyle, map);
}
}
return new LocaleStore(styleMap);
}
if (field == DAY_OF_WEEK) {
for (TextStyle textStyle : TextStyle.values()) {
Map<String, Integer> displayNames = CalendarDataUtility.retrieveJavaTimeFieldValueNames("gregory", Calendar.DAY_OF_WEEK, textStyle.toCalendarStyle(), locale);
Map<Long, String> map = new HashMap<>();
if (displayNames != null) {
for (Entry<String, Integer> entry : displayNames.entrySet()) {
map.put((long) toWeekDay(entry.getValue()), entry.getKey());
}
} else {
// Get names one by one in that case.
for (int wday = Calendar.SUNDAY; wday <= Calendar.SATURDAY; wday++) {
String name;
name = CalendarDataUtility.retrieveJavaTimeFieldValueName("gregory", Calendar.DAY_OF_WEEK, wday, textStyle.toCalendarStyle(), locale);
if (name == null) {
break;
}
map.put((long) toWeekDay(wday), name);
}
}
if (!map.isEmpty()) {
styleMap.put(textStyle, map);
}
}
return new LocaleStore(styleMap);
}
if (field == AMPM_OF_DAY) {
for (TextStyle textStyle : TextStyle.values()) {
if (textStyle.isStandalone()) {
// Stand-alone isn't applicable to AM/PM.
continue;
}
Map<String, Integer> displayNames = CalendarDataUtility.retrieveJavaTimeFieldValueNames("gregory", Calendar.AM_PM, textStyle.toCalendarStyle(), locale);
if (displayNames != null) {
Map<Long, String> map = new HashMap<>();
for (Entry<String, Integer> entry : displayNames.entrySet()) {
map.put((long) entry.getValue(), entry.getKey());
}
if (!map.isEmpty()) {
styleMap.put(textStyle, map);
}
}
}
return new LocaleStore(styleMap);
}
if (field == IsoFields.QUARTER_OF_YEAR) {
// BEGIN Android-changed: Use ICU resources.
/*
// The order of keys must correspond to the TextStyle.values() order.
final String[] keys = {
"QuarterNames",
"standalone.QuarterNames",
"QuarterAbbreviations",
"standalone.QuarterAbbreviations",
"QuarterNarrows",
"standalone.QuarterNarrows",
};
for (int i = 0; i < keys.length; i++) {
String[] names = getLocalizedResource(keys[i], locale);
if (names != null) {
Map<Long, String> map = new HashMap<>();
for (int q = 0; q < names.length; q++) {
map.put((long) (q + 1), names[q]);
}
styleMap.put(TextStyle.values()[i], map);
}
}
*/
ICUResourceBundle rb = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, locale);
ICUResourceBundle quartersRb = rb.getWithFallback("calendar/gregorian/quarters");
ICUResourceBundle formatRb = quartersRb.getWithFallback("format");
ICUResourceBundle standaloneRb = quartersRb.getWithFallback("stand-alone");
styleMap.put(TextStyle.FULL, extractQuarters(formatRb, "wide"));
styleMap.put(TextStyle.FULL_STANDALONE, extractQuarters(standaloneRb, "wide"));
styleMap.put(TextStyle.SHORT, extractQuarters(formatRb, "abbreviated"));
styleMap.put(TextStyle.SHORT_STANDALONE, extractQuarters(standaloneRb, "abbreviated"));
styleMap.put(TextStyle.NARROW, extractQuarters(formatRb, "narrow"));
styleMap.put(TextStyle.NARROW_STANDALONE, extractQuarters(standaloneRb, "narrow"));
// END Android-changed: Use ICU resources.
return new LocaleStore(styleMap);
}
// null marker for map
return "";
}
Aggregations