Internationalization and localization tools


Locale-Sensitive JavaScript Property

str.length;

Internationalization (I18n) Property Overview

This property is set to the length of the string.

For example:

var str = "Hello";
var result = str.length;


Method returns:

result: 5

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

I18n Issues

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

  • If the length is being used as a validation check to prevent entering in too many characters, then this may need to change. Some locales have average string lengths that are 30% greater than what they are in English.
  • The length property applies to the number of 16-bit code point values, rather than the number of characters; it will count Unicode characters that are outside the Basic Multilingual Plane (BMP) as 2 characters since these characters require two 16-bit values (called High Surrogate and Low Surrogate values).

Suggested Replacement

If this is a user-entered string, then the length check may need to increase to handle longer translations. In addition, if the string is to have characters from outside the 16-bit Basic Multilingual Plane, you may need to use a 3rd party JavaScript library to correctly count the number of characters in a string (for example, the punycode.js library, which is bundled with Node.js).


Globalyzer will detect this property and report it as General Pattern 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 and Properties

 

Lingoport internationalization and localization services and software