Internationalization and localization tools


Locale-Sensitive JavaScript Method

number.toString();
number.toString(radix);
date.toString();
boolean.toString();

Internationalization (I18n) Method Overview

This method converts an object to a string and is dependent on the object type. For example, boolean.toString will return a true or false string; number.toString will return a locale-independent (i.e. fixed format) number string based on the radix number system; and date.toString will return a U.S. English formatted date string and in the local system's time zone.

Click here (w3schools) and here (MDN) for additional Number toString method details.

Click here (w3schools) for additional Date toString method details and here (w3schools) for additional Boolean toString method details.

Click here (MDN) for general Object toString method details.

I18n Issues

toString does not take into account the locale of the application; instead the returned strings will always be a fixed format - displaying English in the case of boolean values and date formatting, and using U.S. English numeric notation in the case of number values. You will need to look at each toString call to ensure that boolean, number and date calls are performing as expected once your application supports multiple locales and a time zone other than your system's time zone.

Suggested Replacement

To format dates, times and numbers based on locale and a time zone other than the system time zone, call one of the following methods:

toLocaleDateString
toLocaleString
toLocaleTimeString

In the case of boolean.toString you should instead retrieve a corresponding true/false string from a locale-sensitive resource file.


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