Internationalization and localization tools


Locale-Sensitive JavaScript Method

str.substring(startIndex);
str.substring(startIndex, endIndex);

Internationalization (I18n) Method Overview

This method extracts characters from a string, starting a the 0-based startIndex and up to, but not including endIndex, or the rest of the characters in the string if endIndex isn't specified.

The following example extracts characters from a string:

var str = "Hello";
var result1 = str.substring(1);
var result2 = str.substring(1, 3);
var result3 = str.substring(1, 5);


Method returns:

result1: ello
result2: ell
result3: ello


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

I18n Issues

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

  • The string may need to be translated.
  • The startIndex value may not be correct in a translated string.
  • The endIndex value may not be correct in a translated string.
  • If the string has characters outside the Basic Multilingual Plane, then they require two 16-bit characters; the could be a problem for both the startIndex and the endIndex values.

Suggested Replacement

Use the substring method when the strings are programmatic strings that do not require translation.

If the string is to be displayed to the user, then you may need to first retrieve the string from a resource file based on locale. The startIndex and endIndex values may also need to change if the text is changing.

In addition, if the string is to have characters from outside the 16-bit Basic Multilingual Plane, you will need to count those as two characters when determining the startIndex and endIndex parameters. See the length property for more information.


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