Locale-Sensitive Java Method
java.text.BreakIterator
public static BreakIterator getWordInstance()
public static BreakIterator getWordInstance(Locale locale)
Internationalization (I18n) Method Overview
The BreakIterator class implements methods for finding the location of boundaries in text.
The static, zero-argument call
getWordInstance returns a BreakIterator
instance that detects word boundaries
within a block of text according to the rules of the default locale.
I18n Issues
What users consider to be a word break differs between languages. The
getCharacterInstance method provides two signatures -
one that accepts Locale and one with zero arguments.
When no Locale object is passed in as an argument
the BreakIterator instance operates according to the rules of the default system locale.
These rules might not be correct for all users. For this reason it is good I18n practice to instead use the
signature that accepts a Locale argument.
Globalyzer will detect this method and report it as an I18n issue regardless of the
signature used and regardless of whether it is being used correctly. If
Locale is already being passed as an argument, Globalyzer
will detect it to force developers to double check that the correct Locale
is being passed. If you have determined that the call is being handled correctly, you can
use Globalyzer's Ignore Comment
functionality to ensure that it isn't picked up in a subsequent scan.
Suggested Replacement
public static BreakIterator getWordInstance(
Locale where)
Instead of:
BreakIterator boundary =
BreakIterator.getWordInstance();
Use:
//retrieve the run-time user's locale
Locale aLocale = getUserLocale();
//pass the user's locale as an argument
BreakIterator boundary =
BreakIterator.getWordInstance(aLocale);
Please see the
Java Internationalization Trail for more information about the
BreakIterator class.
Locale-Sensitive Java Methods
|