Internationalization and localization tools


Locale-Sensitive JavaScript Method

str.codePointAt(index)

Internationalization (I18n) Method Overview

This method converts the Unicode character at the 0-based index into a Unicode code point. Unlike charCodeAt, which only supports 16-bit character codes from the Basic Multilingual Plane (BMP), codePointAt supports character codes outside the BMP that require > 16-bit code point values. It does this by detecting and converting High and Low Surrogate character codes to form the Unicode character's code point.

For example:

var str = "\uD800\uDC01"; // requires two 16-bit values: high surrogate + low surrogate = one Unicode character
var result = str.codePointAt(0); // must index at the high-surrogate to get the correct code point value


Method returns:

result: 65537 (or 0x010001)

Click here (MDN) for additional details.

Note: This method is new, part of the ECMAScript 6 proposal, and so may not be supported by all browsers. Until approved, it is also subject to change.

I18n Issues

Whether or not calling codePointAt is an i18n issue is dependent on how it is being used in the application. One possible issue is:

  • This is a string that may have non-English characters; therefore any fixed indexing into the string may result in an unexpected character code.

Suggested Replacement

If the string that is being accessed could have non-English characters, make sure that codePointAt is indexing into the string correctly and that it is handling the possibility of characters greater than 16-bits (i.e. outside the Basic Multilingual Plane of Unicode characters).


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