Internationalization and localization tools


Locale-Sensitive JavaScript Method

array.join();
array.join(separator);

Internationalization (I18n) Method Overview

This method returns a string that is the concatenation of the elements in an array, separated by the separator parameter, or a comma if called without the parameter.

For example:

var arr = ["One", "Two", "Three"];
var result = arr.join("; ");


Method returns:

result: "One; Two; Three"

Click here (w3schools) and here (MDN) for additional details.

I18n Issues

Whether or not calling join is an i18n issue is dependent on how it is being used in the application. If the resulting string is to be displayed to the user, then calling join without the separator parameter may be a problem, since a comma separator is not correct for all locales.

Also, if the array elements are not strings, they will be converted to strings. This can be problematic in an internationalized application; for example, if you have an array of dates or numbers they will be converted to strings without regard for locale.

Suggested Replacement

If the resulting string is user-facing, then make sure that you pass in the separator parameter, retrieving it from a locale-sensitive resource file.

If the array elements are dates or numbers, be sure to apply locale-sensitive formatting before calling join, such as:

toLocaleDateString
toLocaleString
toLocaleTimeString
Intl.DateTimeFormat
Intl.NumberFormat


Globalyzer will detect this method 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 JavaScript Methods

 

Lingoport internationalization and localization services and software