Java Code Examples for com.ibm.icu.impl.ICUResourceBundle#getString()
The following examples show how to use
com.ibm.icu.impl.ICUResourceBundle#getString() .
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: DateIntervalFormat.java From fitnotifications with Apache License 2.0 | 5 votes |
/** * Retrieves the concatenation DateTime pattern from the resource bundle. * @param locale Locale to retrieve. * @return Concatenation DateTime pattern. */ private String getConcatenationPattern(ULocale locale) { ICUResourceBundle rb = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, locale); ICUResourceBundle dtPatternsRb = rb.getWithFallback("calendar/gregorian/DateTimePatterns"); ICUResourceBundle concatenationPatternRb = (ICUResourceBundle) dtPatternsRb.get(8); if (concatenationPatternRb.getType() == UResourceBundle.STRING) { return concatenationPatternRb.getString(); } else { return concatenationPatternRb.getString(0); } }
Example 3
Source File: SimpleDateFormat.java From fitnotifications with Apache License 2.0 | 5 votes |
private static synchronized String getDefaultPattern() { ULocale defaultLocale = ULocale.getDefault(Category.FORMAT); if (!defaultLocale.equals(cachedDefaultLocale)) { cachedDefaultLocale = defaultLocale; Calendar cal = Calendar.getInstance(cachedDefaultLocale); try { // Load the calendar data directly. ICUResourceBundle rb = (ICUResourceBundle) UResourceBundle.getBundleInstance( ICUData.ICU_BASE_NAME, cachedDefaultLocale); String resourcePath = "calendar/" + cal.getType() + "/DateTimePatterns"; ICUResourceBundle patternsRb= rb.findWithFallback(resourcePath); if (patternsRb == null) { patternsRb = rb.findWithFallback("calendar/gregorian/DateTimePatterns"); } if (patternsRb == null || patternsRb.getSize() < 9) { cachedDefaultPattern = FALLBACKPATTERN; } else { int defaultIndex = 8; if (patternsRb.getSize() >= 13) { defaultIndex += (SHORT + 1); } String basePattern = patternsRb.getString(defaultIndex); cachedDefaultPattern = SimpleFormatterImpl.formatRawPattern( basePattern, 2, 2, patternsRb.getString(SHORT), patternsRb.getString(SHORT + 4)); } } catch (MissingResourceException e) { cachedDefaultPattern = FALLBACKPATTERN; } } return cachedDefaultPattern; }
Example 4
Source File: LocaleData.java From fitnotifications with Apache License 2.0 | 5 votes |
/** * Returns the set of exemplar characters for a locale. * * @param options Bitmask for options to apply to the exemplar pattern. * Specify zero to retrieve the exemplar set as it is * defined in the locale data. Specify * UnicodeSet.CASE to retrieve a case-folded exemplar * set. See {@link UnicodeSet#applyPattern(String, * int)} for a complete list of valid options. The * IGNORE_SPACE bit is always set, regardless of the * value of 'options'. * @param extype The type of exemplar set to be retrieved, * ES_STANDARD, ES_INDEX, ES_AUXILIARY, or ES_PUNCTUATION * @return The set of exemplar characters for the given locale. * If there is nothing available for the locale, * then null is returned if {@link #getNoSubstitute()} is true, otherwise the * root value is returned (which may be UnicodeSet.EMPTY). * @exception RuntimeException if the extype is invalid. * @stable ICU 3.4 */ public UnicodeSet getExemplarSet(int options, int extype) { String [] exemplarSetTypes = { "ExemplarCharacters", "AuxExemplarCharacters", "ExemplarCharactersIndex", "ExemplarCharactersCurrency", "ExemplarCharactersPunctuation" }; if (extype == ES_CURRENCY) { // currency symbol exemplar is no longer available return noSubstitute ? null : UnicodeSet.EMPTY; } try{ final String aKey = exemplarSetTypes[extype]; // will throw an out-of-bounds exception ICUResourceBundle stringBundle = (ICUResourceBundle) bundle.get(aKey); if (noSubstitute && !bundle.isRoot() && stringBundle.isRoot()) { return null; } String unicodeSetPattern = stringBundle.getString(); return new UnicodeSet(unicodeSetPattern, UnicodeSet.IGNORE_SPACE | options); } catch (ArrayIndexOutOfBoundsException aiooe) { throw new IllegalArgumentException(aiooe); } catch (Exception ex){ return noSubstitute ? null : UnicodeSet.EMPTY; } }
Example 5
Source File: LocaleData.java From fitnotifications with Apache License 2.0 | 5 votes |
/** * 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. * @stable ICU 3.4 */ 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(); }
Example 6
Source File: LocaleData.java From trekarta with GNU General Public License v3.0 | 5 votes |
/** * Returns the set of exemplar characters for a locale. * * @param options Bitmask for options to apply to the exemplar pattern. * Specify zero to retrieve the exemplar set as it is * defined in the locale data. Specify * UnicodeSet.CASE to retrieve a case-folded exemplar * set. See {@link UnicodeSet#applyPattern(String, * int)} for a complete list of valid options. The * IGNORE_SPACE bit is always set, regardless of the * value of 'options'. * @param extype The type of exemplar set to be retrieved, * ES_STANDARD, ES_INDEX, ES_AUXILIARY, or ES_PUNCTUATION * @return The set of exemplar characters for the given locale. * If there is nothing available for the locale, * then null is returned if {@link #getNoSubstitute()} is true, otherwise the * root value is returned (which may be UnicodeSet.EMPTY). * @exception RuntimeException if the extype is invalid. * @stable ICU 3.4 */ public UnicodeSet getExemplarSet(int options, int extype) { String [] exemplarSetTypes = { "ExemplarCharacters", "AuxExemplarCharacters", "ExemplarCharactersIndex", "ExemplarCharactersCurrency", "ExemplarCharactersPunctuation" }; if (extype == ES_CURRENCY) { // currency symbol exemplar is no longer available return noSubstitute ? null : UnicodeSet.EMPTY; } try{ final String aKey = exemplarSetTypes[extype]; // will throw an out-of-bounds exception ICUResourceBundle stringBundle = (ICUResourceBundle) bundle.get(aKey); if (noSubstitute && !bundle.isRoot() && stringBundle.isRoot()) { return null; } String unicodeSetPattern = stringBundle.getString(); return new UnicodeSet(unicodeSetPattern, UnicodeSet.IGNORE_SPACE | options); } catch (ArrayIndexOutOfBoundsException aiooe) { throw new IllegalArgumentException(aiooe); } catch (Exception ex){ return noSubstitute ? null : UnicodeSet.EMPTY; } }
Example 7
Source File: LocaleData.java From trekarta with GNU General Public License v3.0 | 5 votes |
/** * 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. * @stable ICU 3.4 */ 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(); }
Example 8
Source File: UResourceBundle.java From fitnotifications with Apache License 2.0 | 3 votes |
/** * Returns the string in a given resource at the specified index. * * @param index an index to the wanted string. * @return a string which lives in the resource. * @throws IndexOutOfBoundsException If the index value is out of bounds of accepted values. * @throws UResourceTypeMismatchException If resource bundle type mismatch. * @stable ICU 3.8 */ public String getString(int index) { ICUResourceBundle temp = (ICUResourceBundle)get(index); if (temp.getType() == STRING) { return temp.getString(); } throw new UResourceTypeMismatchException(""); }
Example 9
Source File: UResourceBundle.java From trekarta with GNU General Public License v3.0 | 3 votes |
/** * Returns the string in a given resource at the specified index. * * @param index an index to the wanted string. * @return a string which lives in the resource. * @throws IndexOutOfBoundsException If the index value is out of bounds of accepted values. * @throws UResourceTypeMismatchException If resource bundle type mismatch. * @stable ICU 3.8 */ public String getString(int index) { ICUResourceBundle temp = (ICUResourceBundle)get(index); if (temp.getType() == STRING) { return temp.getString(); } throw new UResourceTypeMismatchException(""); }