com.ibm.icu.text.PluralRules.PluralType Java Examples

The following examples show how to use com.ibm.icu.text.PluralRules.PluralType. 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: PluralRulesLoader.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the functionally equivalent locale.
 */
public ULocale getFunctionalEquivalent(ULocale locale, boolean[] isAvailable) {
    if (isAvailable != null && isAvailable.length > 0) {
        String localeId = ULocale.canonicalize(locale.getBaseName());
        Map<String, String> idMap = getLocaleIdToRulesIdMap(PluralType.CARDINAL);
        isAvailable[0] = idMap.containsKey(localeId);
    }

    String rulesId = getRulesIdForLocale(locale, PluralType.CARDINAL);
    if (rulesId == null || rulesId.trim().length() == 0) {
        return ULocale.ROOT; // ultimate fallback
    }

    ULocale result = getRulesIdToEquivalentULocaleMap().get(
            rulesId);
    if (result == null) {
        return ULocale.ROOT; // ultimate fallback
    }

    return result;
}
 
Example #2
Source File: PluralRulesLoader.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the plural rules for the the locale. If we don't have data,
 * com.ibm.icu.text.PluralRules.DEFAULT is returned.
 */
public PluralRules forLocale(ULocale locale, PluralRules.PluralType type) {
    String rulesId = getRulesIdForLocale(locale, type);
    if (rulesId == null || rulesId.trim().length() == 0) {
        return PluralRules.DEFAULT;
    }
    PluralRules rules = getRulesForRulesId(rulesId);
    if (rules == null) {
        rules = PluralRules.DEFAULT;
    }
    return rules;
}
 
Example #3
Source File: PluralRulesLoader.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the rulesId from the locale,with locale fallback. If there is no
 * rulesId, return null. The rulesId might be the empty string if the rule
 * is the default rule.
 */
public String getRulesIdForLocale(ULocale locale, PluralType type) {
    Map<String, String> idMap = getLocaleIdToRulesIdMap(type);
    String localeId = ULocale.canonicalize(locale.getBaseName());
    String rulesId = null;
    while (null == (rulesId = idMap.get(localeId))) {
        int ix = localeId.lastIndexOf("_");
        if (ix == -1) {
            break;
        }
        localeId = localeId.substring(0, ix);
    }
    return rulesId;
}
 
Example #4
Source File: PluralRulesLoader.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the locales for which we have plurals data. Utility for testing.
 */
public ULocale[] getAvailableULocales() {
    Set<String> keys = getLocaleIdToRulesIdMap(PluralType.CARDINAL).keySet();
    ULocale[] locales = new ULocale[keys.size()];
    int n = 0;
    for (Iterator<String> iter = keys.iterator(); iter.hasNext();) {
        locales[n++] = ULocale.createCanonical(iter.next());
    }
    return locales;
}
 
Example #5
Source File: PluralFormat.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
private void init(PluralRules rules, PluralType type, ULocale locale, NumberFormat numberFormat) {
    ulocale = locale;
    pluralRules = (rules == null) ? PluralRules.forLocale(ulocale, type)
                                  : rules;
    resetPattern();
    this.numberFormat = (numberFormat == null) ? NumberFormat.getInstance(ulocale) : numberFormat;
}
 
Example #6
Source File: PluralRulesObject.java    From es6draft with MIT License 4 votes vote down vote up
private PluralRules createPluralRules() {
    ULocale locale = ULocale.forLanguageTag(this.locale);
    PluralType pluralType = "cardinal".equals(type) ? PluralType.CARDINAL : PluralType.ORDINAL;
    return PluralRules.forLocale(locale, pluralType);
}
 
Example #7
Source File: DefaultLanguagePluralRulesImpl.java    From grammaticus with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public DefaultLanguagePluralRulesImpl(HumanLanguage language) {
	this.language = language;
	this.cardinal = PluralRules.forLocale(language.getLocale(), PluralType.CARDINAL);
	this.ordinal = PluralRules.forLocale(language.getLocale(), PluralType.ORDINAL);
}
 
Example #8
Source File: PluralRulesLoader.java    From fitnotifications with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the lazily-constructed map.
 */
private Map<String, String> getLocaleIdToRulesIdMap(PluralType type) {
    checkBuildRulesIdMaps();
    return (type == PluralType.CARDINAL) ? localeIdToCardinalRulesId : localeIdToOrdinalRulesId;
}
 
Example #9
Source File: MessageFormat.java    From fitnotifications with Apache License 2.0 4 votes vote down vote up
public PluralSelectorProvider(MessageFormat mf, PluralType type) {
    msgFormat = mf;
    this.type = type;
}
 
Example #10
Source File: PluralFormat.java    From fitnotifications with Apache License 2.0 3 votes vote down vote up
/**
 * Sets the locale used by this <code>PluraFormat</code> object.
 * Note: Calling this method resets this <code>PluraFormat</code> object,
 *     i.e., a pattern that was applied previously will be removed,
 *     and the NumberFormat is set to the default number format for
 *     the locale.  The resulting format behaves the same as one
 *     constructed from {@link #PluralFormat(ULocale, PluralRules.PluralType)}
 *     with PluralType.CARDINAL.
 * @param ulocale the <code>ULocale</code> used to configure the
 *     formatter. If <code>ulocale</code> is <code>null</code>, the
 *     default <code>FORMAT</code> locale will be used.
 * @see Category#FORMAT
 * @deprecated ICU 50 This method clears the pattern and might create
 *             a different kind of PluralRules instance;
 *             use one of the constructors to create a new instance instead.
 */
@Deprecated
public void setLocale(ULocale ulocale) {
    if (ulocale == null) {
        ulocale = ULocale.getDefault(Category.FORMAT);
    }
    init(null, PluralType.CARDINAL, ulocale, null);
}
 
Example #11
Source File: PluralFormat.java    From fitnotifications with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new <code>PluralFormat</code> for a plural type, a
 * pattern and a locale.
 * @param ulocale the <code>PluralFormat</code> will be configured with
 *        rules for this locale. This locale will also be used for standard
 *        number formatting.
 * @param type The plural type (e.g., cardinal or ordinal).
 * @param pattern the pattern for this <code>PluralFormat</code>.
 * @param numberFormat The number formatter to use.
 * @throws IllegalArgumentException if the pattern is invalid.
 */
/*package*/ PluralFormat(ULocale ulocale, PluralType type, String pattern, NumberFormat numberFormat) {
    init(null, type, ulocale, numberFormat);
    applyPattern(pattern);
}
 
Example #12
Source File: PluralFormat.java    From fitnotifications with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new cardinal-number <code>PluralFormat</code> for the default <code>FORMAT</code> locale.
 * This locale will be used to get the set of plural rules and for standard
 * number formatting.
 * @see Category#FORMAT
 * @stable ICU 3.8
 */
public PluralFormat() {
    init(null, PluralType.CARDINAL, ULocale.getDefault(Category.FORMAT), null);
}
 
Example #13
Source File: PluralFormat.java    From fitnotifications with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new <code>PluralFormat</code> for a plural type, a
 * pattern and a locale.
 * @param ulocale the <code>PluralFormat</code> will be configured with
 *        rules for this locale. This locale will also be used for standard
 *        number formatting.
 * @param type The plural type (e.g., cardinal or ordinal).
 * @param  pattern the pattern for this <code>PluralFormat</code>.
 * @throws IllegalArgumentException if the pattern is invalid.
 * @stable ICU 50
 */
public PluralFormat(ULocale ulocale, PluralType type, String pattern) {
    init(null, type, ulocale, null);
    applyPattern(pattern);
}
 
Example #14
Source File: PluralFormat.java    From fitnotifications with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new cardinal-number <code>PluralFormat</code> for a given set of rules, a
 * pattern and a locale.
 * @param ulocale the <code>PluralFormat</code> will be configured with
 *        rules for this locale. This locale will also be used for standard
 *        number formatting.
 * @param rules defines the behavior of the <code>PluralFormat</code>
 *        object.
 * @param  pattern the pattern for this <code>PluralFormat</code>.
 * @throws IllegalArgumentException if the pattern is invalid.
 * @stable ICU 3.8
 */
public PluralFormat(ULocale ulocale, PluralRules rules, String pattern) {
    init(rules, PluralType.CARDINAL, ulocale, null);
    applyPattern(pattern);
}
 
Example #15
Source File: PluralFormat.java    From fitnotifications with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new cardinal-number <code>PluralFormat</code> for a given set of rules and a
 * pattern.
 * The standard number formatting will be done using the default <code>FORMAT</code> locale.
 * @param rules defines the behavior of the <code>PluralFormat</code>
 *        object.
 * @param  pattern the pattern for this <code>PluralFormat</code>.
 * @throws IllegalArgumentException if the pattern is invalid.
 * @see Category#FORMAT
 * @stable ICU 3.8
 */
public PluralFormat(PluralRules rules, String pattern) {
    init(rules, PluralType.CARDINAL, ULocale.getDefault(Category.FORMAT), null);
    applyPattern(pattern);
}
 
Example #16
Source File: PluralFormat.java    From fitnotifications with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new cardinal-number <code>PluralFormat</code> for a given pattern string and
 * locale.
 * The locale will be used to get the set of plural rules and for
 * standard number formatting.
 * <p>Example code:{@.jcite com.ibm.icu.samples.text.pluralformat.PluralFormatSample:---PluralFormatExample}
 * @param ulocale the <code>PluralFormat</code> will be configured with
 *        rules for this locale. This locale will also be used for standard
 *        number formatting.
 * @param  pattern the pattern for this <code>PluralFormat</code>.
 * @throws IllegalArgumentException if the pattern is invalid.
 * @stable ICU 3.8
 */
public PluralFormat(ULocale ulocale, String pattern) {
    init(null, PluralType.CARDINAL, ulocale, null);
    applyPattern(pattern);
}
 
Example #17
Source File: PluralFormat.java    From fitnotifications with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new cardinal-number <code>PluralFormat</code> for a given pattern string.
 * The default <code>FORMAT</code> locale will be used to get the set of plural rules and for
 * standard number formatting.
 * @param  pattern the pattern for this <code>PluralFormat</code>.
 * @throws IllegalArgumentException if the pattern is invalid.
 * @see Category#FORMAT
 * @stable ICU 3.8
 */
public PluralFormat(String pattern) {
    init(null, PluralType.CARDINAL, ULocale.getDefault(Category.FORMAT), null);
    applyPattern(pattern);
}
 
Example #18
Source File: PluralFormat.java    From fitnotifications with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new <code>PluralFormat</code> for the plural type.
 * The standard number formatting will be done using the given {@link java.util.Locale}.
 * @param locale the default number formatting will be done using this
 *        locale.
 * @param type The plural type (e.g., cardinal or ordinal).
 * @stable ICU 54
 */
public PluralFormat(Locale locale, PluralType type) {
    this(ULocale.forLocale(locale), type);
}
 
Example #19
Source File: PluralFormat.java    From fitnotifications with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new <code>PluralFormat</code> for the plural type.
 * The standard number formatting will be done using the given locale.
 * @param ulocale the default number formatting will be done using this
 *        locale.
 * @param type The plural type (e.g., cardinal or ordinal).
 * @stable ICU 50
 */
public PluralFormat(ULocale ulocale, PluralType type) {
    init(null, type, ulocale, null);
}
 
Example #20
Source File: PluralFormat.java    From fitnotifications with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new cardinal-number <code>PluralFormat</code> for a given set of rules.
 * The standard number formatting will be done using the given locale.
 * @param ulocale the default number formatting will be done using this
 *        locale.
 * @param rules defines the behavior of the <code>PluralFormat</code>
 *        object.
 * @stable ICU 3.8
 */
public PluralFormat(ULocale ulocale, PluralRules rules) {
    init(rules, PluralType.CARDINAL, ulocale, null);
}
 
Example #21
Source File: PluralFormat.java    From fitnotifications with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new cardinal-number <code>PluralFormat</code> for a given set of rules.
 * The standard number formatting will be done using the default <code>FORMAT</code> locale.
 * @param rules defines the behavior of the <code>PluralFormat</code>
 *        object.
 * @see Category#FORMAT
 * @stable ICU 3.8
 */
public PluralFormat(PluralRules rules) {
    init(rules, PluralType.CARDINAL, ULocale.getDefault(Category.FORMAT), null);
}
 
Example #22
Source File: PluralFormat.java    From fitnotifications with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new cardinal-number <code>PluralFormat</code> for a given locale.
 * @param ulocale the <code>PluralFormat</code> will be configured with
 *        rules for this locale. This locale will also be used for standard
 *        number formatting.
 * @stable ICU 3.8
 */
public PluralFormat(ULocale ulocale) {
    init(null, PluralType.CARDINAL, ulocale, null);
}