Internationalization and localization tools


Locale-Sensitive Perl Method

setlocale( LC_ALL, "en_US" );

Internationalization (I18n) Method Overview

The POSIX::setlocale function modifies the program's underlying locale. May be used to set the variable LC_ALL (for all locale settings), or the less overarching LC_CTYPE (character type), LC_COLLATE (collation), LC_MONETARY (monetary formatting), LC_NUMERIC (numeric format) and LC_TIME(time/date format). Also, LANG, which is used as a fallback if the other variables are unset.

See perl's POSIX function documentation, perllocale's locale categories and setlocale documentation for additional details.

I18n Issues

The use of setlocale is typical in internationalized applications, and does not constitute an i18n issue by itself. However, its usage should still be double checked to confirm proper locale sensitivity in the application. Locale choices are system dependent. Use caution when hard coding a locale. Do not use the "C" locale for internationalized applications.

Additionally, if the locale is set while multiple threads are executing, the locale will change for all threads. Undefined behavior may result, possibly including segfaults.

Suggested Replacement

Double check usage of setlocale to ensure that it will be managed in a manner appropriate for all target locales. Use caution when hard coding locales. Avoid the "C" locale. Do not set the locale while multiple threads exist.

Globalyzer will detect this function and report it as an i18n issue. 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.



Locale-Sensitive Perl Methods

 

Lingoport internationalization and localization services and software