Internationalization and localization tools


Locale-Sensitive JavaScript Method

String.fromCharCode(num, ...)

Internationalization (I18n) Method Overview

This static method converts one or more Unicode values into a string of characters (not a String object).

For example:

var result = String.fromCharCode(72, 101, 108, 108, 111);


Method returns:

result: "Hello"

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

I18n Issues

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

  • The character codes are creating a string that is dependent on the language of the locale.
  • The character codes only support characters within the Basic Multilingual Plane (BMP); outside the BMP requires 2 character codes to form the complete character (called the High Surrogate character and the Low Surrogate character codes).

Suggested Replacement

Use the String.fromCharCode static method when the string will contain only ASCII (0-127 code points) characters; i.e. a programmatic string. If the string is to be displayed in a UI, then it would be best to retrieve the string from a locale-sensitive resource file. Otherwise, if you are creating a string that needs to support characters from outside the Basic Multilingual Plane, consider using String.fromCodePoint, which supports the higher code points.


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