Internationalization and localization tools


Locale-Sensitive JavaScript Method

str.search(searchStringOrRegExp);

Internationalization (I18n) Method Overview

This method searches for the match specified by the searchStringOrRegExp parameter, returning the 0-based index to the first occurrence, or -1 if the search fails. If a simple string is passed in rather than a RegExp, it will be converted to a regular expression using new RegExp(searchString).

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

I18n Issues

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

  • The string may need to be translated.
  • If the parameter is a simple string, then it may need to be translated.
  • If the first parameter is a RegExp then there could be a problem because RegExp does not support all Unicode characters.

Suggested searchment

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

If the string is to be displayed to the user, then you may need to first retrieve the string from a resource file based on locale. The searchString parameter may also need to change if the text is changing.

In addition, if the string is to have non-English characters and you are using a RegExp , you may need to refactor this call to support all Unicode characters. See RegExp for more information on its Unicode character support.


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