Internationalization and localization tools


Locale-Sensitive JavaScript Method

str.match(regExp);

Internationalization (I18n) Method Overview

This method applies the regExp (regular expression object or literal) to the string, returning the an array with the resulting matches, or null if no match was found.

The following example searches for words in the string, using a regular expression literal:

var str = "This is a sentence.";
var resultArray = str.match(/\w+/g);


Method returns an array with 4 strings:

resultArray: This,is,a,sentence

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

I18n Issues

Whether or not calling match is an i18n issue is dependent on how it is being used in the application. If the string that is to be searched is to be displayed to the user, then this may be a problem because:

  • RegExp does not support all Unicode characters.
  • The regExp parameter may need to be translated.
  • Assuming that spaces are word breaks is not valid for all locales.

Suggested Replacement

Use the match method when the strings are programmatic strings that do not require translation.

If the string is to be displayed to the user, or is entered by the user, then you will need to use a 3rd party regular expression object that supports Unicode rather than RegExp, which means you will need to use a method other than match.

Matching on words will need to be refactored, since some locales do not separate words with spaces.


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