ULocale uLocale = ULocale.forLanguageTag("pl-PL"); ResourceBundle resources = ResourceBundle.getBundle( "path.to.messages", uLocale.toLocale()); PluralRules pluralRules = PluralRules.forLocale(uLocale); double[] numbers = { 0, 1, 1.5, 2, 2.5, 3, 4, 5, 5.5, 11, 12, 23 }; for (double number : numbers) { String resourceKey = "some.message.plural_form." + pluralRules.select(number); String message = "!" + resourceKey + "!"; try { message = resources.getString(resourceKey); System.out.println(format(message, uLocale, number)); } catch (MissingResourceException e) { // Log this } }
/** Creates a new Java Locale object from this LocaleId. * @return a new Java Locale object based on the best match for the given LocaleId, * or null if an error occurred. */ public Locale toJavaLocale() { return uLocale.toLocale(); }
/** * Constructs a SimpleDateFormat using the given pattern and locale. * <b>Note:</b> Not all locales support SimpleDateFormat; for full * generality, use the factory methods in the DateFormat class. * @stable ICU 3.2 */ public SimpleDateFormat(String pattern, ULocale loc) { this(pattern, loc.toLocale()); }
/** * Constructs a SimpleDateFormat using the given pattern and locale. * <b>Note:</b> Not all locales support SimpleDateFormat; for full * generality, use the factory methods in the DateFormat class. * @stable ICU 3.2 */ public SimpleDateFormat(String pattern, ULocale loc) { this(pattern, loc.toLocale()); }
/** * Constructs a calendar with the specified time zone and locale. * @param zone the time zone to use * @param locale the ulocale for the week data * @stable ICU 3.2 */ protected Calendar(TimeZone zone, ULocale locale) { calendar = java.util.Calendar.getInstance(zone.timeZone, locale.toLocale()); }
/** * Create a DecimalFormatSymbols object for the given locale. * @param locale the locale * @stable ICU 3.2 */ public DecimalFormatSymbols(ULocale locale) { this(new java.text.DecimalFormatSymbols(locale.toLocale())); }
/** * {@icu} Returns a new instance of BreakIterator that locates legal line- * wrapping positions. * @param where A Locale specifying the language of the text being broken. * @return A new instance of BreakIterator that locates legal * line-wrapping positions. * @stable ICU 3.2 */ public static BreakIterator getLineInstance(ULocale where) { return getBreakInstance(where.toLocale(), KIND_LINE); }
/** * Returns a particular kind of BreakIterator for a locale. * Avoids writing a switch statement with getXYZInstance(where) calls. * @internal * @deprecated This API is ICU internal only. */ public static BreakIterator getBreakInstance(ULocale where, int kind) { return getBreakInstance(where.toLocale(), KIND_SENTENCE); }
/** * Returns a calendar with the specified time zone and locale. * @param zone the time zone to use * @param locale the ulocale for the week data * @return a Calendar. * @stable ICU 3.2 */ public static synchronized Calendar getInstance(TimeZone zone, ULocale locale) { return new Calendar(java.util.Calendar.getInstance(zone.timeZone, locale.toLocale())); }
/** * Create a DecimalFormatSymbols object for the default locale. * @stable ICU 2.0 */ public DecimalFormatSymbols() { this(new java.text.DecimalFormatSymbols(ULocale.getDefault(Category.FORMAT).toLocale())); }
/** * Empty constructor. Public for compatibility with JDK which lets the * compiler generate a default public constructor even though this is * an abstract class. * @stable ICU 2.6 */ public NumberFormat() { this(java.text.NumberFormat.getInstance(ULocale.getDefault(Category.FORMAT).toLocale())); }
/** * {@icu} Returns a <code>DateFormat</code> appropriate to this calendar. * Subclasses wishing to specialize this behavior should override * {@link #handleGetDateFormat}. * @stable ICU 3.2 */ public DateFormat getDateTimeFormat(int dateStyle, int timeStyle, ULocale loc) { return getDateTimeFormat(dateStyle, timeStyle, loc.toLocale()); }
/** * {@icu} Returns a new instance of BreakIterator that locates logical-character * boundaries. * @param where A Locale specifying the language of the text being analyzed. * @return A new instance of BreakIterator that locates logical-character * boundaries. * @stable ICU 3.2 */ public static BreakIterator getCharacterInstance(ULocale where) { return getBreakInstance(where.toLocale(), KIND_CHARACTER); }
/** * Returns a particular kind of BreakIterator for a locale. * Avoids writing a switch statement with getXYZInstance(where) calls. * @internal * @deprecated This API is ICU internal only. */ public static BreakIterator getBreakInstance(ULocale where, int kind) { return getBreakInstance(where.toLocale(), KIND_SENTENCE); }
/** * {@icu} Returns a <code>DateFormat</code> appropriate to this calendar. * Subclasses wishing to specialize this behavior should override * {@link #handleGetDateFormat}. * @stable ICU 3.2 */ public DateFormat getDateTimeFormat(int dateStyle, int timeStyle, ULocale loc) { return getDateTimeFormat(dateStyle, timeStyle, loc.toLocale()); }
/** * Gets the time formatter with the default formatting style * for the default locale. * @return a time formatter. * @stable ICU 2.0 */ public final static DateFormat getTimeInstance() { return new DateFormat(java.text.DateFormat.getTimeInstance( java.text.DateFormat.DEFAULT, ULocale.getDefault(Category.FORMAT).toLocale())); }
/** * Returns a default date/time formatter that uses the SHORT style for both the * date and the time. * @stable ICU 2.0 */ public final static DateFormat getInstance() { return new DateFormat(java.text.DateFormat.getDateTimeInstance( java.text.DateFormat.SHORT, java.text.DateFormat.SHORT, ULocale.getDefault(Category.FORMAT).toLocale())); }
/** * Returns a calendar using the specified time zone and default locale. * @param zone the time zone to use * @return a Calendar. * @stable ICU 2.0 */ public static synchronized Calendar getInstance(TimeZone zone) { return new Calendar(java.util.Calendar.getInstance(zone.timeZone, ULocale.getDefault(Category.FORMAT).toLocale())); }