Web UI Framework localization - setting locale-specific formats

You can set up locale-specific formats according to your locale standards.

You can set the following locale-specific formats in a JavaScript file:
  • Date/time
  • Decimal
  • E-mail
  • Phone number
  • Credit card

The validation.js file is a localizable file. This file is available at install/repository/eardata/platform_uifwk/<version>/war/platform/scripts/, where <version> is the Sterling Application Platform version being consumed by the application.

You can copy this validation.js file into <install>/repository/eardata/platform_uifwk/<version>/war/localization/<locale_directories>/platform/scripts/ and modify it as needed.

The <locale_directories> variable uses the format <language>/<country>/<variant>. The <variant> variable is optional. So for <locale_directory>, you could have fr/FR for fr_FR or en/US/EST for en_US_EST. If the <variant> folder doesn't exist, the system will search for the file under the <language>/<country >folder. The <country> variable is also optional, but only when <variant> is not specified. For a locale fr_FR_WIN, you can have fr/FR/WIN, fr/FR, or fr/, but not fr/WIN.

This validation.js file is given priority over the validation.js file in the <install>/repository/eardata/platform_uifwk/version/war/platform/scripts/directory.

After the localization is finished, the JavaScript file must be minified.

Date/time formats

Date and time formats can vary among countries or regions. For example, April 2, 2003 could be written as 02/04/03 in one country or region and 04/02/03 in another country or region. You can use the validation.js file to localize date/time formats.

In validation.js, all date/time formats are in the PHP format. The validation.js file includes a Java-to-PHP conversion table.

User date/time formats are set as follows:

sc.plat.Userprefs.setDateFormat('m/d/Y');
sc.plat.Userprefs.setTimeFormat('H:i:s');
sc.plat.Userprefs.setTimestampFormat('Y-m-d\\TH:i:sP');
sc.plat.Userprefs.setMonthDisplayDateFormat('F Y');
sc.plat.Userprefs.setDayDisplayDateFomrat('N j');
sc.plat.Userprefs.setHourMinuteTimeFormat('H:i');
sc.plat.Userprefs.setDateHourMinuteFormat('m/d/Y H:i');

Server date/time formats are set as follows:

sc.plat.info.Application.setDateFormat('Y-m-d');
sc.plat.info.Application.setTimeFormat('H:i:s');
sc.plat.info.Application.setTimestampFormat('Y-m-d\\TH:i:sP');
The validation.js file also defines the following methods for converting the date/time between the server and user formats. In a localized file these methods can be modified.
  • sc.plat.DateFormatter.dateFormatConverter

    Converts the date between the server and user formats.

  • sc.plat.DateFormatter.timeFormatConverter

    Converts the time between the server and user formats.

EXT specific formats

You can localize the following Ext specific locale formats using the platformExtLocaleSpecificFormatsHolderObj object in the validation.js file:

platformExtLocaleSpecificFormatsHolderObj = function() {
   return ({
   //Provide the Date format that should be displayed in the error message for
   //Date. Ideally, this should be in java format.
   getDisplayDateFormat: function() {
      var displayDateFormat = "MM/dd/yyyy";
      return displayDateFormat;
   }
   //Provide the suffixes to add to numbers. For example: 1st, 2nd, 3rd, 4th
   //and so on.
   , getNumberSuffixes: function() {
      var numberSuffixes = "(?:st|nd|rd|th)";
      return numberSuffixes;
   }
   //AM Time in lower case. am/pm stands for AM/PM (before noon/after noon) in
   //lower case.
   , getAMString: function() {
      var amString = "am";
      return amString;
   }
   //PM Time in lower case.. am/pm stands for AM/PM (before noon/after noon) in
   //lower case.
   , getPMString: function() {
      var pmString = "pm";
      return pmString;
   }
   //Alternate Date formats for current locale.
   , getAltDateFormats: function() {
      var altDateFormats = "m/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d|Y-m-d";
      return altDateFormats;
   }
   //Date format for PropertyColumn.
   , getPropertyColumnModelDateFormat: function() {
      var propertyColModelDateFormat = "m/j/Y";
      return propertyColModelDateFormat;
   }
   //The number format to use for NumberColumn. This is Ext 3 specific.
   , getNumberColumnDefaultFormat: function() {
      var numberColFormat = "0,000.00";
      return numberColFormat;
   }
   //The Time format for TimeField in current locale.
   , getDefaultTimeFormatString: function() {
      var defaultTimeFormatString = "g:i A";
      return defaultTimeFormatString;
   }
   //Alternate Time formats for current locale.
   , getAltTimeFormats: function() {
      var altTimeFormats = "g:ia|g:iA|g:i a|g:i A|h:i|g:i|H:i|ga|ha|gA|h a|g a|
g A|gi|hi|gia|hia|g|H"; return altTimeFormats; } }); }();
Note:
  • All the Ext specific formats mentioned in the sample code above will work for most of the locales.
  • The Date format provided in the getDisplayDateFormat() function is used to indicate the correct Date format for a particular locale. Ideally, this should be in java format.

Date format differences betweenJava andJavaScript

Make sure that you use the proper date formatting (Java™ or JavaScript) to accurately format dates for locales. In JavaScript, the PHP/Ext JS format is supported.

The date formats in Java and JavaScript are not the same. The date 01/03/2010 is in the "MM/dd/yyyy" format in Java, which is equivalent to "m/d/Y" in JavaScript. In the same way, the date 1/3/10 (notice the missing zeros in the date and month) is in the "M/d/yy" format in Java, which is equivalent to "n/j/y" in JavaScript.

Type SimpleDate
Format (Java)
PHP (Ext JS Supported) Range Example
Year yyyy Y - 2003
yy y - 03
Month M n 1-12 7, 10
MM m 01-12 07, 10
MMM M Jan-Dec Mar, Jul
MMMM F January-December March, July
Day in Month d j 1-31 5, 22
dd d 01-31 1, 22
Hour h g 1-12 1, 12
hh h 01-12 01, 12
H G 0-23 0, 23
HH H 00-23 00, 23
K - 0-11 0, 11
KK - 00-11 00, 11
k - 1-24 1, 24
kk - 01-24 01, 24
Minute m - 0-59 0, 59
  mm i 00-59 00, 59
Seconds s - 0-59 0, 59
  ss s 00-59 00, 59
  S u 001-999 001, 999
Day in Week - N 1-7 4
  E D - Tue
  EEE D - Tue
  EEEE l - Tuesday
Day in Year D(1-365/366) - 1-365/366 2, 30, 234
  DD(1-365/366) - 01-365/366 02, 30, 234
  DDD(1-365/366) - 001-365/366 002, 030, 234
  - z 0-364 0, 203
Day of Week in Month F - 1-7 1-7
Week in Year w W 1-53 1-53
Week in Month W - 1-5 1-5
Meridiem - a am-pm pm
  a A AM-PM AM
Time Zone Z - - IST
  Z Z - +530

Decimal separator

The decimal format is set as follows:
sc.plat.Userprefs.setDecimalSeparator(".");
For example, in a German locale, this format would be set to:
sc.plat.Userprefs.setDecimalSeparator(",");

Grouping separator

The digits in a number are grouped by using a separator (comma, period, or any other per locale) specified in the following method:
sc.plat.Userprefs.setGroupingSeperator();
For example, to use a comma as the digit separator, use the following:
sc.plat.Userprefs.setGroupingSeperator(",");
Note: Decimal and grouping separators for a locale must be different to avoid distortion of values.

Grouping and formatting numbers

The following method can be used to format and group the number according to the value specified. The default group size is set to "3". To change this grouping, you must provide your own implementation for this method in your locale specific validation.js file.
sc.plat.NumberFormatter.formatNumber("3");

For example, if the group size is set t o"3" , the number 1000000 is displayed as 1,000,000, where "," is the grouping separator.

E-mail addresses, phone number, and credit card formats

The formats for e-mail addresses, phone numbers, and credit cards are set as follows. In a localized file, you can register new validators that are specific to a locale.
  • sc.plat.ValidateUtils.registerValidator ('email',sc.plat.ValidateUtils.emailFormatValidator);
  • sc.plat.ValidateUtils.registerValidator ('creditcard',sc.plat.ValidateUtils.creditCardFormatValidator);
  • sc.plat.ValidateUtils.registerValidator ('phone',sc.plat.ValidateUtils.phoneNumberFormatValidator);