Internationalization and localization tools


Locale-Sensitive Java Method

java.text.BreakIterator

public static BreakIterator getLineInstance()

public static BreakIterator getLineInstance(Locale locale)

Internationalization (I18n) Method Overview

The BreakIterator class implements methods for finding the location of boundaries in text. The zero-argument, static call getLineInstance returns a BreakIterator instance that can be used to detect line boundaries within a block of text according to the rules of the system's default locale.

I18n Issues

What users consider to be a line break differs across languages languages. The getLineInstance 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 getLineInstance(
   Locale where)

Instead of:

BreakIterator boundary =
  BreakIterator.getLineInstance();

Use:

//retrieve the run-time user's locale
Locale aLocale = getUserLocale();

//pass the user's locale as an argument
BreakIterator boundary =
  BreakIterator.getLineInstance(aLocale);

Please see the Java Internationalization Trail for more information about the BreakIterator class.

Locale-Sensitive Java Methods

 

Lingoport internationalization and localization services and software