|
Locale-Sensitive Perl MethodInternationalization (I18n) Method Overview
The See perl's sprintf function documentation for additional details. I18n IssuesString 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: sprintf $fh "The %s played with the ball for %d hour%s.", "dog", 2, "s"; .
See Wikipedia: Word Order and Mozilla's guide to Localization and Plurals for more details. Note that, while LC_NUMERIC is considered by sprintf, its only affect 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
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 hour%s"), 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.
|