Java Code Examples for com.ibm.icu.impl.ICUResourceBundle#getStringWithFallback()
The following examples show how to use
com.ibm.icu.impl.ICUResourceBundle#getStringWithFallback() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RelativeDateTimeFormatter.java From fitnotifications with Apache License 2.0 | 6 votes |
private String getDateTimePattern(ICUResourceBundle r) { String calType = r.getStringWithFallback("calendar/default"); if (calType == null || calType.equals("")) { calType = "gregorian"; } String resourcePath = "calendar/" + calType + "/DateTimePatterns"; ICUResourceBundle patternsRb = r.findWithFallback(resourcePath); if (patternsRb == null && calType.equals("gregorian")) { // Try with gregorian. patternsRb = r.findWithFallback("calendar/gregorian/DateTimePatterns"); } if (patternsRb == null || patternsRb.getSize() < 9) { // Undefined or too few elements. return "{1} {0}"; } else { int elementType = patternsRb.get(8).getType(); if (elementType == UResourceBundle.ARRAY) { return patternsRb.get(8).getString(0); } else { return patternsRb.getString(8); } } }
Example 2
Source File: MeasureFormat.java From fitnotifications with Apache License 2.0 | 5 votes |
/** * Return a formatter (compiled SimpleFormatter pattern) for a range, such as "{0}–{1}". * @param forLocale locale to get the format for * @param width the format width * @return range formatter, such as "{0}–{1}" * @internal * @deprecated This API is ICU internal only. */ @Deprecated public static String getRangeFormat(ULocale forLocale, FormatWidth width) { // TODO fix Hack for French if (forLocale.getLanguage().equals("fr")) { return getRangeFormat(ULocale.ROOT, width); } String result = localeIdToRangeFormat.get(forLocale); if (result == null) { ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle. getBundleInstance(ICUData.ICU_BASE_NAME, forLocale); ULocale realLocale = rb.getULocale(); if (!forLocale.equals(realLocale)) { // if the child would inherit, then add a cache entry for it. result = localeIdToRangeFormat.get(forLocale); if (result != null) { localeIdToRangeFormat.put(forLocale, result); return result; } } // At this point, both the forLocale and the realLocale don't have an item // So we have to make one. NumberingSystem ns = NumberingSystem.getInstance(forLocale); String resultString = null; try { resultString = rb.getStringWithFallback("NumberElements/" + ns.getName() + "/miscPatterns/range"); } catch ( MissingResourceException ex ) { resultString = rb.getStringWithFallback("NumberElements/latn/patterns/range"); } result = SimpleFormatterImpl.compileToStringMinMaxArguments( resultString, new StringBuilder(), 2, 2); localeIdToRangeFormat.put(forLocale, result); if (!forLocale.equals(realLocale)) { localeIdToRangeFormat.put(realLocale, result); } } return result; }
Example 3
Source File: LocaleData.java From fitnotifications with Apache License 2.0 | 5 votes |
/** * Returns LocaleDisplaySeparator for this locale. * @return locale display separator as a char. * @stable ICU 4.2 */ 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; }
Example 4
Source File: LocaleData.java From trekarta with GNU General Public License v3.0 | 5 votes |
/** * Returns LocaleDisplaySeparator for this locale. * @return locale display separator as a char. * @stable ICU 4.2 */ 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; }
Example 5
Source File: DateIntervalInfo.java From fitnotifications with Apache License 2.0 | 4 votes |
private void setup(ULocale locale) { int DEFAULT_HASH_SIZE = 19; fIntervalPatterns = new HashMap<String, Map<String, PatternInfo>>(DEFAULT_HASH_SIZE); // initialize to guard if there is no interval date format defined in // resource files fFallbackIntervalPattern = "{0} \u2013 {1}"; try { // Get the correct calendar type String calendarTypeToUse = locale.getKeywordValue("calendar"); if ( calendarTypeToUse == null ) { String[] preferredCalendarTypes = Calendar.getKeywordValuesForLocale("calendar", locale, true); calendarTypeToUse = preferredCalendarTypes[0]; // the most preferred calendar } if ( calendarTypeToUse == null ) { calendarTypeToUse = "gregorian"; // fallback } // Instantiate the sink to process the data and the resource bundle DateIntervalSink sink = new DateIntervalSink(this); ICUResourceBundle resource = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, locale); // Get the fallback pattern String fallbackPattern = resource.getStringWithFallback(CALENDAR_KEY + "/" + calendarTypeToUse + "/" + INTERVAL_FORMATS_KEY + "/" + FALLBACK_STRING); setFallbackIntervalPattern(fallbackPattern); // Already loaded calendar types Set<String> loadedCalendarTypes = new HashSet<String>(); while (calendarTypeToUse != null) { // Throw an exception when a loop is detected if (loadedCalendarTypes.contains(calendarTypeToUse)) { throw new ICUException("Loop in calendar type fallback: " + calendarTypeToUse); } // Register the calendar type to avoid loops loadedCalendarTypes.add(calendarTypeToUse); // Get all resources for this calendar type String pathToIntervalFormats = CALENDAR_KEY + "/" + calendarTypeToUse; resource.getAllItemsWithFallback(pathToIntervalFormats, sink); // Get next calendar type to load if there was an alias pointing at it calendarTypeToUse = sink.getAndResetNextCalendarType(); } } catch ( MissingResourceException e) { // Will fallback to {data0} - {date1} } }
Example 6
Source File: LocaleData.java From fitnotifications with Apache License 2.0 | 4 votes |
/** * Returns LocaleDisplayPattern for this locale, e.g., {0}({1}) * @return locale display pattern as a String. * @stable ICU 4.2 */ public String getLocaleDisplayPattern() { ICUResourceBundle locDispBundle = (ICUResourceBundle) langBundle.get(LOCALE_DISPLAY_PATTERN); String localeDisplayPattern = locDispBundle.getStringWithFallback(PATTERN); return localeDisplayPattern; }
Example 7
Source File: LocaleData.java From trekarta with GNU General Public License v3.0 | 4 votes |
/** * Returns LocaleDisplayPattern for this locale, e.g., {0}({1}) * @return locale display pattern as a String. * @stable ICU 4.2 */ public String getLocaleDisplayPattern() { ICUResourceBundle locDispBundle = (ICUResourceBundle) langBundle.get(LOCALE_DISPLAY_PATTERN); String localeDisplayPattern = locDispBundle.getStringWithFallback(PATTERN); return localeDisplayPattern; }