Internationalization and localization tools


Locale-Sensitive Perl Method

printf FILEHANDLE FORMAT, LIST

Internationalization (I18n) Method Overview

The printf function formats text and prints it to the given filehandle.

See perl's printf function documentation for additional details.

I18n Issues

String formatting is i18n sensitive as word order is highly locale dependent. For instance, some languages expect statements to be in the form of Subject Verb Object, while others might be Subject Object Verb. Additionally, pluralization rules change between languages, and formatting must take this into account. A problematic example would be:

printf $fh "The %s played with the ball for %d hours.", "dog", 2;.

See Wikipedia: Word Order and Mozilla's guide to Localization and Plurals for more details.

Note that, while LC_NUMERIC is considered by printf, its only effect is to change the decimal separator value. E.g. '1.23' vs '1,23'. Other formatting, such as thousands separators or positive/negative signs may not be properly localized. See POSIX::localeconv for a list of locale sensitive formatting settings.

Suggested Replacement

The POSIX::localeconv function should be used to help perform locale specific formatting. Also see perllocale's information on localeconv.

When possible, avoid formatting user-facing text in ways that are sensitive to word order. If you must format text this way, externalize the entire to-be-formatted string ("The %s played with the ball for %d hours"), along with the arguments to resource files. Ideally noting that they are related. This way translators can re-arrange the formatted string's contents and make more informed translation decisions.

Avoid "hour%s" Esq hacks for pluralization. It's better have entirely separate strings. e.g. "hour", "hours". Note that different languages have numerous forms of pluralization rules beyond this. See Mozilla's guide to Localization and Plurals. Consider a CLDR approach.

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