Internationalization and localization tools


Locale-Sensitive JavaScript Method

str.replace(searchStringOrRegExp, replaceStringOrFunction);

Internationalization (I18n) Method Overview

This method searches for the searchStringOrRegExp and if found, replaces it with the replaceStringOrFunction, returning the new string. The first parameter may be a string or a RegExp object; the second parameter can be a simple string, or a function call that will be called for each match. To get replacement for all matches, a RegExp object and its g flag.

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

I18n Issues

Whether or not calling replace 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.
  • The searchString may need to be translated.
  • The replaceString 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 Replacement

Use the replace 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 and replaceString parameters 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 object, you will need to refactor this call to support all Unicode characters. See RegExp for more information.


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