Internationalization and localization tools


Locale-Sensitive JavaScript Method

encodeURIComponent(string);

Internationalization (I18n) Method Overview

The encodeURIComponent method encodes a URI (Uniform Resource Identifier) component, replacing specific characters with their hexadecimal UTF-8 encoded values, with up to 3 encoded values representing characters from the Basic Multilingual Plane (BMP). When the character is outside the BMP, the high and low surrogate characters are encoded using 4 UTF-8 encoded values. In addition to the special characters encoded by encodeURI, encodeURIComponent encodes the following characters: = ? & , / : @ + $ #

In the following example, the Chinese characters and other special characters have been replaced with their hexadecimal UTF-8 encoded values:

var str = "test.html?name1=漢One Two&name2=𠀐Three";
var result = encodeURIComponent(str);

Method returns:

result: test.html%3Fname%3D%E6%BC%A2One%20Two%26name2%3D%F0%A0%80%90Three

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

I18n Issues

While the method itself supports all Unicode characters, the URI may contain user-facing text that requires translation.

Suggested Replacement

If the URI is to contain text that is displayed to the user, you may need to retrieve the locale-sensitive text from a resource file and then call encodeURIComponent on the URI. Also, make sure that decodeURIComponent is called to decode the URI.


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