View on GitHub

TAU

TAU (Tizen Advanced UI) project for supporting web app development based on web-based ui widget components library

Globalize Utility

The TAU Globalize utility supports internationalization and localization. It wraps the Globalize functionality for easy access from Tizen Web applications, and it is extended to support the right-to-left (RTL) languages.

jQuery and Globalize

Globalize is a jQuery JavaScript library for internationalization and localization that leverages the official Unicode CLDR JSON data. The library works both for the browser and as a Node.js module. jQuery and Globalize have dependencies with cldr.js, which is a CLDR low-level manipulation tool.

Globalize :

CLDR Data

The Unicode CLDR provides the key building blocks for software to support the world’s languages. It includes

CLDR uses the XML format provided by UTS #35: Unicode Locale Data Markup Language (LDML). LDML is a format used not only for CLDR, but also for the general interchange of locale data. For more information about CLDR, see CLDR release notes, and to download the JSON format file , see JSON Data from the Unicode CLDR Project.

The TAU Globalize utility uses the CLDR 26 release, and when you create a Tizen Web application project, you find CLDR in the /lib/tau/js/cldr-data folder.

Using the Globalize Utility

To use the TAU Globalize utility in your application

1. Download the following dependency files for your application

2. Create a folder structure, as shown in the following table.

| Folder structure| |:—:|:—:|:—:| | structure | case2 ||

   
Folder structure Description
cldr/ Copy the cldr.js library in this folder.
cldr-data/ Copy the cldr-data files in this folder. </br> cldr-data/main: Copy the languages to be supported in this folder.
globalize/ Copy the Globalize library in this folder.
locale/ Make the custom locale string in this folder.
script/ JavaScript files.
style/ CSS, image, and other style related files.
view/ HTML files

3. Set the locale using the following example code:

var globalize = tau.util.globalize,
   localeId  = "ko-KR";
document.addEventListener('pageshow', function()
{
   globalize.setLocale(localeId)
   .done(function(ko)
   { 
      /* "ko" is the Globalize utility instance */
      console.log(ko.getLocale()) /* "ko" */
   })
})

The setLocale() method is not synchronous, and it returns the deferred object with the methods then(), done(), and fail(). Use these methods to receive the Globalize utility instance.

You can specify locales in 2 ways using IETF language tags, such as en, pt-BR, or zh-Hant-TW:

If no lang attribute or setLocale() input argument is defined, the Globalize utility finds the locale by checking the window.navigator.language property. If the check result is false, the utility uses the default locale “en”.

The following table illustrates the locale setting method order.

Order Locale setting methods
1 setLocale(LocaleId)
2 <body lang="ko-KR"\>
3 window.navigator.language
4 Default locale “en”

4. Make sure that you have all required CLDR files.

The setLocale() method automatically loads the basic CLDR data files which are match the given locale by local AJAX. During the method call, the Globalize utility also loads the basic CLDR JSON files:

In addition to the basic files, each Globalize method requires a specialset of CLDR portions. Determine which Globalize module functionalities you need, and make sure you have the required files, as defined in the following table.

Table: CLDR requirements  
Core module cldr/supplemental/likelySubtags.json
Date module cldr/main/locale/ca-gregorian.json </br> cldr/main/locale/timeZoneNames.json </br> cldr/supplemental/timeData.json </br> cldr/supplemental/weekData.json </br> CLDR JSON files from the number module
Number module cldr/main/locale/numbers.json </br> cldr/supplemental/numberingSystems.json
Plural module cldr/supplemental/plurals.json (for cardinals) </br> cldr/supplemental/ordinals.json (for ordinals)

5. Using the Globalize Utility Methods

The following code snippets show how to use the TAU Globalize utility methods:

var globalize = tau.util.globalize,
    localeId  = "ko-KR",
    currency_unit = "KRW"; /* ISO 4217 */

document.addEventListener('pageshow', function()
{
   globalize.setLocale(localeId)
   .done(function(ko)
   {
      console.log(ko.formatCurrency(69000, currency_unit)); /* ₩69,900 */
   })
})

For more information, see the currency unit standard in ISO 4217.

For more information, see date-formatter.

The calendar format is specified in the gregorian.json file in the CLDR data.

This method returns a function that formats a message using the ICU message format pattern. For more information, see message-formatter.

  1. Create a locale resource in the locales path: { "en": { "formatter": { "welcome":"Hello Mr. {0}", "thankyou":"Bye Mr. {custom}." } } }
  2. Use the messageFormatter() method: ``` var globalize = tau.util.globalize, localeId = “en-US”;

document.addEventListener(‘pageshow’, function() { globalize.setLocale(localeId) .done(function(en) { var welcomeFormatter = en.messageFormatter(‘formatter/welcome’), thankyouFormatter = en.messageFormatter(‘formatter/thankyou’),
welcomeMessageList = [“Tom”], thankyouMessageList = {custom:”Tom”};

     console.log(welcomeFormatter(welcomeMessageList));   
     console.log(thankyouFormatter(thankyouMessageList));
  })    })    ```

Right-to-left (RTL) Language Support

TAU offers 2 ways to handle right-to-left (RTL) languages:

When the setLocale() method is called, it automatically applies a CSS class to the body element of your DOM if the given locale has an RTL direction.

he following examples show how to use the locale-specific CSS

``` * The following example uses the locale-specific CSS to switch on the RTL feature for a UI component: ``` .ui-script-direction-rtl .ui-listview { direction: rtl; } .ui-script-direction-rtl .ui-li.ui-li-static { text-align: right; unicode-bidi: bidi-override; } ``` The following example shows how to use the RTL property in a locale object (the rtl variable). If a given locale has an RTL direction, the variable is true. ``` var globalize = tau.util.globalize, localeId = "ar-EG"; document.addEventListener('pageshow', function() { globalize.setLocale(localeId) .done(function(ar) { console.log(ar.rtl) /* true */ }) }) ```