ResourceBundle
objects.
Translatable text includes status messages, error messages, log file
entries, and GUI component labels. This text is hardcoded into programs
that haven't been internationalized. You need to locate all occurrences
of hardcoded text that is displayed to end users. For example, you
should clean up code like this:
String buttonLabel = "OK"; ... JButton okButton = new JButton(buttonLabel);
See the section Isolating Locale-Specific Data for details.
Integer fileCount; ... String diskStatus = "The disk contains " + fileCount.toString() + " files.";
Double amount; TextField amountField; ... String displayAmount = amount.toString(); amountField.setText(displayAmount);
You should replace the preceding code with a routine that formats the number correctly. The Java programming language provides several classes that format numbers and currencies. These classes are discussed in the section Numbers and Currencies.
Date currentDate = new Date(); TextField dateField; ... String dateString = currentDate.toString(); dateField.setText(dateString);
If you use the date-formatting classes, your application can display dates and times correctly around the world. For examples and instructions, see the section Dates and Times.
char ch; ... if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) // WRONG!
if
statement misses
the character ü in the German word Grün.
The Character
comparison methods use the Unicode standard
to identify character properties. Thus you should replace the previous
code with the following:
char ch; ... if (Character.isLetter(ch))
Character
comparison methods,
see the section
Checking Character Properties.
String
class. A program that hasn't been internationalized might compare
strings as follows:
String target; String candidate; ... if (target.equals(candidate)) { ... if (target.compareTo(candidate) < 0) { ...
The String.equals
and String.compareTo
methods perform binary comparisons, which are ineffective when sorting
in most languages. Instead you should use the Collator
class, which is described in the section
Comparing Strings.
Characters in the Java programming language are encoded in Unicode. If your application handles non-Unicode text, you might need to translate it into Unicode. For more information, see the section Converting Non-Unicode Text.