Internationalization and localization tools


Locale-Sensitive JavaScript Method

str.split();
str.split(separator);
str.split(separator, limit);

Internationalization (I18n) Method Overview

This method creates an array of substrings by using the separator string (or regular expression) to determine where the splits should be. If separator is not specified, then the resulting array will contain just one entry which will be the entire string. Use limit is specify the maximum number of substrings in the array.

For example:

var str = "One Two Three";
var result = str.split(" ", 2);


Method returns:

result: {"One", "Two"}

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

I18n Issues

Whether or not calling split is an i18n issue is dependent on how it is being used in the application. If the string that is to be split is to be displayed to the user, then this may be a problem because:

  • The string may need to be translated.
  • The separator may need to vary based on locale.
  • Assuming that spaces are word breaks is not valid for all locales.
  • If the separator is a regular expression, it will not support all Unicode characters, see RegExp

Suggested Replacement

If the string is user-facing, it will need be translated by retrieving it from a locale-sensitive resource file.

Searching for characters that may not exist in translated strings (such as spaces) will need to be refactored. You may need to also retrieve the separator from a locale-sensitive resource file.

If the string is to be displayed to the user, or is entered by the user, and the separator is a regular expression, then you will need to use a 3rd party regular expression object that supports all Unicode characters (for example, XRegExp).


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