Internationalization and localization tools


Locale-Sensitive JavaScript Method

decodeURIComponent(string);

Internationalization (I18n) Method Overview

The decodeURIComponent method decodes a URI (Uniform Resource Identifier) component that has been encoded by calling encodeURIComponent. decodeURIComponent converts hexadecimal UTF-8 encoded values back to their display values, supporting all Unicode characters, even those outside the the Basic Multilingual Plane (BMP), which require two 16-bit values (or four UTF-8 hexadecimal values).

In the following example, the Chinese characters and spaces have been encoded with their hexadecimal UTF-8 values and are then decoded to their original values:

var str = "test.html%3Fname%3D%E6%BC%A2One%20Two%26name2%3D%F0%A0%80%90Three";
var result = decodeURIComponent(str);

Method returns:

result: test.html?name1=漢One Two&name2=𠀐Three

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

I18n Issues

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

Suggested Replacement

Make sure that you call encodeURIComponent to encode the URI. If the URI is to contain text that is displayed to the user, you may need to first retrieve the text from a resource file based on the application's locale.


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