Java Cookbook
resourcebundle
Problem:
You want to use the correct forms for plurals in a sentence including dynamic values.
Solution:
Plurals can be very difficult to deal with. It is not always as easy as adding an s to the end of a word. Consider the sentence, "Enter your child(rens)'s names(s)." That looks pretty ugly, and not human at all.
ChoiceFormat allows us to spcify blocks of text that appear depending upon a numeric value passed in. For example:
Problem:
You want to combine dynamic values with your static resource files.
Solution:
There are many situations where part of a sentence comes from a dynamic source, or is provided by the user. Obviously translatng a sentence for every possible scenario is not an option. Thankfully Java provides a solution for this situation. It is called MessageFormat.
A message format is a way of replacing variables in a sentence in a locale sensitive manner.
A simple message format:
If you are testing any of these recipes in Eclipse and the characters are not displaying correctly in your console visit http://i18ncookbook.com/eclipse_settings.
This site is ad supported. I hope you find something among our sponsors worth clicking. ;)
i18n search