Internationalization and localization tools


Locale-Sensitive JavaScript Constructor

Intl.Collator();
Intl.Collator(locales);
Intl.Collator(locales, options);

Internationalization (I18n) Method Overview

This constructor compares two strings, using the default locale when there are no locales passed in, else using the locales and optional options, returning 0 if the strings are equal, -1 if the base string sorts before compareString or 1 if the base string sorts after compareString.

For example:

var str1 = "Turkish ı"; // dotless ı
var str2 = "Turkish i"; // dotted i
var collator = new Intl.Collator("tr-TR");
var result = collator.compare(str1, str2);


Method returns:

result: -1 // The dotless ı sorts before the dotted i

Click here for additional details.

I18n Issues

Whether or not calling Intl.Collator is an i18n issue is dependent on how it is being used in the application. Internationalization issues may occur because:

  • The base string may need to be translated.
  • The compareString may need to be translated.
  • Intl.Collator is based on the default locale rather than the application locale when the locales parameter is not specified.

Suggested Replacement

If strings are user-facing, they may need be translated by retrieving them from a locale-sensitive resource file.

Be sure to pass in the locales parameter to ensure sorting based on the application locale. Include options as needed to fine-tune the collation.


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