Git Product home page Git Product logo

ecma402's Introduction

ecma402 Build Status

This project provides an implementation of the ECMA-402 JavaScript Internationalization APIs standard for number formatting ( Intl.NumberFormat ) and date and time formatting ( Intl.DateTimeFormat ). Collation ( Intl.Collator ) is not currently supported.

Status

Current release is version 1.0, published 2015-07-08.

Licensing

This project is distributed by the Dojo Foundation and licensed under the "New" BSD License. All contributions require a Dojo Foundation CLA.

Dependencies

This project requires the following other projects to run:

Installation

Bower release installation:

$ bower install ecma402

Manual master installation:

$ git clone git://github.com/ibm-js/ecma402.git

Then install dependencies with bower (or manually from github if you prefer to):

$ cd ecma402
$ bower install

Documentation

Once installed, you should first include RequireJS AMD loader in your appication:

<script src="bower_components/requirejs/require.js"></script>

Then you can load Intl through the ecma402/IntlShim module and use it:

<script>
   // configuring RequireJS
   require.config({
     // where to find ecma402 package
     baseUrl: "bower_components",
     // which locales do I want to be available in addition to default browser locale
     config: {
        "ecma402/locales": /^(en|de|fr)$/
     }
   });
</script>
<script>
  require(["ecma402/IntlShim"], function(Intl) {
     var nf = Intl.NumberFormat("fr", { style: "percent" });
     console.log(nf.format(24.02));
  });
</script>

Note that by default IntlShim will use native implementation if available in the browser, if not available it will load its own JavaScript CLDR-based implementation. In order to force the JavaScript implementation you can force the intl-api flag to false in the RequireJS config as follows:

<script>
   // configuring RequireJS
   require.config({
     // where to find ecma402 package
     baseUrl: "bower_components",
     config: {
       "requirejs-dplugins/has": {
       	  "intl-api": false
       }
     }
   });
</script>

Alternatively, if you always want to use the Intl as provided through this package, and not attempt to leverage the native support in the browser, you can load the ecma402/Intl module directly, as follows:

<script>
   // configuring RequireJS
   require.config({
     // where to find ecma402 package
     baseUrl: "bower_components",
     // which locales do I want to be available in addition to default browser locale
     config: {
        "ecma402/locales": /^(en|de|fr)$/
     }
   });
</script>
<script>
  require(["ecma402/Intl"], function(Intl) {
     var nf = Intl.NumberFormat("fr", { style: "percent" });
     console.log(nf.format(24.02));
  });
</script>

For further documentation on the ECMA-402 standard Intl API and how to use it you can check out the information available at MDN

Locale configuration using ecma402/locales

This package contains locale data for a large number of locales as defined by Unicode CLDR For many run time environments, it is not necessary to load the data for all possible locales, but instead, only for the default locale as defined by the settings in the browser. In order to keep the data load time to a minimum, by default only data associated with the default locale is loaded at run time unless additional locales are specified using the config option "ecma402/locales" as in the above example. The argument can be either a regular expression, a string (for a single locale), or an array of strings.

ecma402's People

Contributors

ahmedmustafa avatar ccmitchellusa avatar cjolif avatar clmath avatar jcemmons avatar wkeese avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.