Locale-Sensitive JavaScript Method
str.concat(string1, string2, ...)
Internationalization (I18n) Method Overview
This method appends one or more strings to the base string, returning a new combined string.
For example:
var str = "Page ";
var result = str.concat("1", " of ", "5");
Method returns:
result: "Page 1 of 5"
Click here (w3schools) and
here (MDN) for additional details.
I18n Issues
Whether or not calling concat is an i18n issue is dependent on how it is being used in the application. If the concatenated
string is to be displayed to the user, then this may be a problem because:
- The order of the concatenated strings is fixed rather than being dependent on the language.
- The strings themselves are hardcoded in the source file rather than being retrieved based on locale.
Suggested Replacement
Use the str.concat method when the concatenated strings are programmatic strings that do not require translation.
If the string is to be displayed to the user, then you must first replace the concatenated strings with a single string that includes insertion points
for any dynamic part. From our example above, this could look something like this:
var STR_PageNofY="Page {0} of {1}";
Then, the concat method should be replaced with a retrieval method that retrieves the string, based on locale,
and replaces the insertion points with the dynamic strings (such as a person's name or a number). From our example, this could look something like this:
getI18nString(STR_PageNofY, curPage, totPages);
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
|