Internationalization and localization tools


Locale-Sensitive JavaScript Method

string.charAt(index)

Internationalization (I18n) Method Overview

This method returns a string representing the character at the 0-based index of the string, or an empty string if index is out of range.

For example:

var str = "Hello";
var result = str.charAt(1);


Method returns:

result: "e"

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

I18n Issues

Whether or not calling charAt is an i18n issue is dependent on how it is being used in the application. Some possible issues are:

  • This is a string that may have non-English characters; therefore any fixed indexing into the string may result in an unexpected character.
  • This is a string that may have characters outside the Basic Multilingual Plane (BMP), and so requires 2 characters (called the High Surrogate character and the Low Surrogate character) to form the complete, displayable character.

Suggested Replacement

Use the charAt method when the string will contain only ASCII (0-127 code points) characters; i.e. a programmatic string. If you are searching for a specific locale-independent character in a translated string, call indexOf which returns the index of the character. If you must call charAt on a non-English string (for example, you are looking for a specific translated character in a translated string), then make sure that you handle the fact that a translated string will have different characters in different locations and that you may need to support characters outside the Basic Multilingual Plane.


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