2

I usejava.util.ResourceBundle for i18n like this:

try {
  resourceBundle = ResourceBundle.getBundle("Messages", locale);
} catch (MissingResourceException ex) {
  logger.log(Level.SEVERE, ex.getMessage(), ex);
}

String localizedString = resourceBundle.getString("key");

I want to create the plural forms are well. Like:

one object
two objects

How can I define plural forms of localized Strings?

Michael
  • 32,527
  • 49
  • 210
  • 370

2 Answers2

3

Here is how Java handles plural forms:

https://docs.oracle.com/javase/tutorial/i18n/format/choiceFormat.html

1

A ResourceBundle doesn't deal with pluralization. It just allows getting values associated with keys, based on a locale.

To have pluralized translations, use different keys, or use a ChoiceFormat. Note that MessageFormat can use a ChoiceFormat by specifying it in its pattern.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255