From b65bd8fcc850bfbdae2fa079c857f48f34992d3c Mon Sep 17 00:00:00 2001 From: Andrzej Popowski Date: Fri, 13 May 2016 15:30:34 +0200 Subject: [PATCH] [Cordova - Globalization] - adding guide and tutorial Change-Id: Ief414a99ca875f7b195971e850fca7acb0eeff63 Signed-off-by: Andrzej Popowski --- org.tizen.guides/html/index.htm | 1 + .../html/web/tizen/cordova/cordova_guide_w.htm | 1 + .../html/web/tizen/cordova/globalization_w.htm | 109 ++++++ org.tizen.tutorials/html/index.htm | 1 + .../html/web/tizen/cordova/cordova_tutorials_w.htm | 2 + .../web/tizen/cordova/globalization_tutorial_w.htm | 383 +++++++++++++++++++++ 6 files changed, 497 insertions(+) create mode 100644 org.tizen.guides/html/web/tizen/cordova/globalization_w.htm create mode 100644 org.tizen.tutorials/html/web/tizen/cordova/globalization_tutorial_w.htm diff --git a/org.tizen.guides/html/index.htm b/org.tizen.guides/html/index.htm index ffb0218..69f6a1a 100644 --- a/org.tizen.guides/html/index.htm +++ b/org.tizen.guides/html/index.htm @@ -310,6 +310,7 @@
  • Device Motion
  • Dialogs
  • File Transfer
  • +
  • Globalization
  • Network Information
  • diff --git a/org.tizen.guides/html/web/tizen/cordova/cordova_guide_w.htm b/org.tizen.guides/html/web/tizen/cordova/cordova_guide_w.htm index f8a038d..eb6429d 100644 --- a/org.tizen.guides/html/web/tizen/cordova/cordova_guide_w.htm +++ b/org.tizen.guides/html/web/tizen/cordova/cordova_guide_w.htm @@ -42,6 +42,7 @@
  • Dialogs

    Make different types of input dialog boxes and notifications to the user.

  • Network Information

    information about connection (cellular, WiFi, ethernet, etc.) and connection related events

  • File Transfer

    How to download and upload files using Cordova

  • +
  • Globalization

    How to obtain information and performs operations specific to the user's locale, language and timezone

  • diff --git a/org.tizen.guides/html/web/tizen/cordova/globalization_w.htm b/org.tizen.guides/html/web/tizen/cordova/globalization_w.htm new file mode 100644 index 0000000..22806a7 --- /dev/null +++ b/org.tizen.guides/html/web/tizen/cordova/globalization_w.htm @@ -0,0 +1,109 @@ + + + + + + + + + + + + + Globalization + + + + + +
    +

    Globalization

    + +

    +The Globalization API gives the possibility to get information about user's locale, language and timezone. It also enables to convert strings, numbers and dates according the user's locale. +

    + + + + + + + + + + +
    Note
    You need to wait for deviceready event before using Globalization Cordova API. +
    document.addEventListener( "deviceready", onDeviceReady );
    +
    +function onDeviceReady() {
    +    //Cordova is ready...
    +}
    +
    + +

    +All functions (ie. getPrefferedLanguage, getLocaleName etc.) are accesible by the navigator.globalization object. +

    + +

    Obtaining locale information

    +

    +With the Globalization API you can obtain the following locale information: +

      +
    • User's current language BCP 47 identifier (eg. en-US). See the example.
    • +
    • User's current locale BCP 47 identifier (eg. en-US). See the example.
    • +
    • Pattern string to format and parse currency and ISO 4217 currency code. See the example.
    • +
    • Names of months and names of the days of the week. See the example.
    • +
    • Pattern string to format and parse dates. See the example.
    • +
    • First day of the week. See the example.
    • +
    • Pattern string to format and parse numbers. See the example.
    • +
    • Is Daylight Saving Time in effect for a given date. See the example.
    • +
    +

    + +

    Converting data

    +

    + With the Globalization API you can convert strings, numbers and dates according to the user's locale. The following conversions are available: +

      +
    • date to string - see the example.
    • +
    • string to date - see the example.
    • +
    • number to string - see the example.
    • +
    • string to number - see the example.
    • +
    +

    + + + +
    + +Go to top + + + + + + + diff --git a/org.tizen.tutorials/html/index.htm b/org.tizen.tutorials/html/index.htm index f10a54e..cb1e70e 100644 --- a/org.tizen.tutorials/html/index.htm +++ b/org.tizen.tutorials/html/index.htm @@ -325,6 +325,7 @@
  • Dialogs
  • Network Information
  • File Transfer
  • +
  • Globalization
  • diff --git a/org.tizen.tutorials/html/web/tizen/cordova/cordova_tutorials_w.htm b/org.tizen.tutorials/html/web/tizen/cordova/cordova_tutorials_w.htm index ce5b92a..ff02c87 100644 --- a/org.tizen.tutorials/html/web/tizen/cordova/cordova_tutorials_w.htm +++ b/org.tizen.tutorials/html/web/tizen/cordova/cordova_tutorials_w.htm @@ -48,6 +48,8 @@

    Demonstrates how you can retrieve information about connection (cellular, WiFi, ethernet, etc.) and how to use connection related events

  • File Transfer: transfering files

    Demonstrates how to download and upload files using Cordova API

  • +
  • Globalization: managing locale, language and timezone +

    Demonstrates how to obtain information and performs operations specific to the user's locale, language and timezone using Cordova API

  • diff --git a/org.tizen.tutorials/html/web/tizen/cordova/globalization_tutorial_w.htm b/org.tizen.tutorials/html/web/tizen/cordova/globalization_tutorial_w.htm new file mode 100644 index 0000000..58a7482 --- /dev/null +++ b/org.tizen.tutorials/html/web/tizen/cordova/globalization_tutorial_w.htm @@ -0,0 +1,383 @@ + + + + + + + + + + + + + Globalization + + + + + + +
    + +

    Globalization

    + +

    This tutorial demonstrates how to obtain the user's locale information and how to convert data according to this locale.

    + +

    Current language

    +

    +The following example demonstrates how to get the current BCP 47 language identifier. +

    +
     // When the browser is set to the en-US language,
    + // this should output the text
    + // similar to the results that follow.
    +
    + navigator.globalization.getPreferredLanguage(
    +   function (language) { console.log('Language: ' + language.value); },
    +   function () { console.log('Error getting language.'); }
    + );
    +

    +The output: +

    +
    Language: en-US
    + +

    Current locale

    +

    +The following example demonstrates how to get current BCP 47 locale identifier. +

    +
     // When the browser is set to the en-US language,
    + // this should output the text
    + // similar to the results that follow.
    +
    + navigator.globalization.getLocaleName(
    +   function (locale) { console.log('Locale: ' + locale.value); },
    +   function () { console.log('Error getting locale.'); }
    + );
    +

    +The output: +

    +
    Locale: en-US
    + +

    Currency

    +

    +The following example demontrates how to obtain information about currency. It containsr: +

      +
    • The currency pattern to format and parse the currency values. The patterns follow Unicode Technical Standard #35.
    • +
    • The ISO 4217 currency code.
    • +
    • The number of fractional digits.
    • +
    • The rounding increment.
    • +
    • The decimal symbol.
    • +
    • The grouping symbol.
    • +
    +

    +
     // When the browser is set to the en-US locale and the selected
    + // currency is United States Dollars, this example outputs
    + // text similar to the results that follow.
    +
    + navigator.globalization.getCurrencyPattern(
    +   'USD',
    +   function (pattern) {
    +     console.log('pattern: '  + pattern.pattern);
    +     console.log('code: ' + pattern.code);
    +     console.log('fraction: ' + pattern.fraction);
    +     console.log('rounding: ' + pattern.rounding);
    +     console.log('decimal: '  + pattern.decimal);
    +     console.log('grouping: ' + pattern.grouping);
    +   },
    +   function () { console.log('Error getting pattern.'); }
    + );
    +

    +The output: +

    +
    pattern: $#,##0.##;($#,##0.##)
    +code: USD
    +fraction: 2
    +rounding: 0
    +decimal: .
    +grouping: ,
    + +

    Names of the months and names of the days of the week

    +

    +This example demonstrates how to obtain names of months. The 3rd argument is { type: 'wide', item: 'months' }. It causes that names of months are obtained. If you want to obtain names of days of the week, you should pass { type: 'wide', item: 'days' } as a 3rd argument. +

    +
     // When the browser is set to the en_US locale,
    + // this example logs the names of months, as per locale settings,
    + // with text similar to the results that follow.
    +
    + navigator.globalization.getDateNames(
    +   function (names) {
    +     for (var i = 0; i < names.value.length; i++) {
    +       console.log('month: ' + names.value[i]);
    +     }
    +   },
    +   function () { console.log('Error getting names.'); },
    +   { type: 'wide', item: 'months' }
    + );
    +

    +The output: +

    +
    month: January
    +month: February
    +month: March
    +month: April
    +month: May
    +month: June
    +month: July
    +month: August
    +month: September
    +month: October
    +month: November
    +month: December
    + +

    Date format

    +

    +The following example demonstrates how to get information about date format. It contains: +

      +
    • The date and time pattern that follows Unicode Technical Standard #35.
    • +
    • The abbreviated name of the time zone.
    • +
    • The current difference in seconds between the client's time zone and coordinated universal time.
    • +
    • The current daylight saving time offset in seconds between the client's non-daylight saving time zone and the client's daylight saving time zone.
    • +
    +

    +
     // This example displays the locale date pattern.
    + // When the browser is set to the en_US locale,
    + // the text displayed is similar to the results that follow.
    +
    + function checkDatePattern () {
    +   navigator.globalization.getDatePattern(
    +     function (date) { console.log('Date pattern: ' + date.pattern); },
    +     function () { console.log('Error getting pattern'); },
    +     { formatLength: 'short', selector: 'date and time' }
    +   );
    + }
    +
    + checkDatePattern();
    +

    +The output: +

    +
    Date pattern: M/d/yyyy h:mm a
    + +

    First day of the week

    +

    +This example demonstrates how to obtain information which day is the first day of the week. 1 means Sunday. +

    +
     // When the browser is set to the en_US locale,
    + // this outputs the text similar to "day: 1".
    +
    + navigator.globalization.getFirstDayOfWeek(
    +   function (day) { console.log('day: ' + day.value); },
    +   function () { console.log('Error getting first day of week.'); }
    + );
    +

    +The output: +

    +
    day: 1
    + +

    Number format

    +

    +This example demonstrates how to obtain information about number format. It contains: +

      +
    • The number pattern that follows Unicode Technical Standard #35.
    • +
    • The symbol to use when formatting and parsing, such as percent or currency symbol. It depends on the 3rd argument of the function getNumberPattern which can be 'decimal', 'percent' or 'currency'.
    • +
    • The number of fractional digits.
    • +
    • The rounding increment
    • +
    • The symbol to use for positive numbers
    • +
    • The symbol to use for negative numbers
    • +
    • The decimal symbol
    • +
    • The grouping symbol
    • +
    +

    +
     // When the browser is set to the en_US locale,
    + // this example outputs the text
    + // similar to the results that follow.
    +
    + navigator.globalization.getNumberPattern(
    +   function (pattern) {
    +     console.log('pattern: '  + pattern.pattern);
    +     console.log('symbol: '   + pattern.symbol);
    +     console.log('fraction: ' + pattern.fraction);
    +     console.log('rounding: ' + pattern.rounding);
    +     console.log('positive: ' + pattern.positive);
    +     console.log('negative: ' + pattern.negative);
    +     console.log('decimal: '  + pattern.decimal);
    +     console.log('grouping: ' + pattern.grouping);
    +   },
    +   function() { console.log('An error occurred.'); },
    +   { type: 'decimal' }
    + );
    +

    +The output: +

    +
    pattern: #,##0.###
    +symbol: .
    +fraction: 0
    +rounding: 0
    +positive:
    +negative: -
    +decimal: .
    +grouping: ,
    + +

    Daylight Saving Time

    +

    +This example shows how to obtain information whether or not daylight savings time is in effect for a given date using current time zone. +

    +
     // During the summer, and if the browser
    + // is set to a DST-enabled timezone,
    + // this should log text similar to "dst: true":
    +
    + navigator.globalization.isDayLightSavingsTime(
    +   new Date(),
    +   function (date) { console.log('dst: ' + date.dst); },
    +   function () { console.log('Error getting the DST state.'); }
    + );
    +

    +The output: +

    +
    dst: true
    + +

    Conversions

    +

    +This example demontrates how to make conversion between strings, numbers and dates according to current locale. +

    +
      +
    • Date to String - converts date formatted to a string according to the client's locale and timezone. +
       // When the browser is set to the en-US language,
      + // this should output text similar to the results that follow.
      + // This example uses the default conversion options.
      +
      + navigator.globalization.dateToString(
      +   new Date(),
      +   function (date) { console.log('Date: ' + date.value); },
      +   function () { console.log('Error getting dateString.'); },
      +   { formatLength: 'short', selector: 'date and time' }
      + );
      +

      +The output: +

      +
      Date: 9/25/2012 4:21PM
      +
    • +
    • String to Date - converts a date formatted as a DOMString to a date object according to the client's locale and timezone. +
       // when the browser is set to the en_US locale,
      + // this example outputs text similar to the results that follow.
      + // Note that the month integer is one less than the string,
      + // as the month integer represents an array index.
      +
      + navigator.globalization.stringToDate(
      +     '9/25/2012',
      +     function (date) {
      +       console.log('month: '  + date.month +
      +                   ', day: '  + date.day   +
      +                   ', year: ' + date.year)
      +     },
      +     function () { console.log('Error getting date.'); },
      +     { selector: 'date' }
      + );
      +

      +The output: +

      +
      month: 8, day: 25, year: 2012
      +
    • +
    • Number to String - returns a number formatted as a string according to the client's user preferences. +
       // When the browser is set to the en_US locale,
      + // this code displays the results that follow.
      +
      + navigator.globalization.numberToString(
      +    3.1415926,
      +    function (number) { console.log('decimal number: ' + number.value); },
      +    function () { console.log('Error getting number.'); },
      +    { type: 'decimal' }
      + );
      +
      + navigator.globalization.numberToString(
      +    1000003,
      +    function (number) { console.log('big decimal number: ' + number.value); },
      +    function () { console.log('Error getting number.'); },
      +    { type: 'decimal' }
      + );
      +
      + navigator.globalization.numberToString(
      +    0.3183099,
      +    function (number) { console.log('percentile: ' + number.value); },
      +    function () { console.log('Error getting number.'); },
      +    { type: 'percent' }
      + );
      +
      + navigator.globalization.numberToString(
      +    1099.95,
      +    function (number) { console.log('currency: ' + number.value); },
      +    function () { console.log('Error getting number'); },
      +    { type: 'currency' }
      + );
      +

      +The output: +

      +
      decimal number: 3.142
      +big decimal number: 1,000,003
      +percentile: 32%
      +currency: $1,099.95
      +
    • +
    • String to Number - parses a number formatted as a string according to the client's user preferences and returns the corresponding number. +
       // When the browser is set to the en_US locale,
      + // this should display the text similar to the results that follow.
      +
      + navigator.globalization.stringToNumber(
      +     '1234.56',
      +     function (number) { console.log('number: ' + number.value); },
      +     function () { console.log('Error getting number.'); },
      +     { type: 'decimal' }
      + );
      +

      +The output: +

      +
      number: 1234.56
      +
    • +
    + + + + +
    + +Go to top + + + + + + + -- 2.7.4