dojo.cldr¶
Status: | Draft |
---|---|
Version: | 1.0 |
Project owner: | Adam Peller |
Available: | since 1.0? |
Contents
Contains data from the Common Locale Data Repository (CLDR) http://unicode.org/cldr with associated utility classes
Introduction¶
This data contains tables with culturally sensitive information for hundreds of languages and country variants, such as translations of days of the week, months of the year, patterns for formatting dates and numbers. This is used by dojo.date, dojo.number, and dojo.currency to produce localized output. The nls/ directory as provided in the standard download of Dojo contains a subset of the available locales; a complete set is available by running the ant script in util/buildscripts/cldr. See the section “Buildscripts” below for more information. It is therefore usually not necessary to hand-craft localized copies of this information. The unicode.org CLDR project is responsible for the choices made in these files and has both a bug tracker and survey application on their website.
Usage¶
The data is transformed, as a pre-build step, from XML data to JSON-style Javascript you see under the nls/ directory. This data is used by other modules in core Dojo such as dojo.date, dojo.number and dojo.currency, which provides more friendly programmatic APIs. It usually is not necessary to use dojo.cldr.nls directly. Other packages available in the CLDR provide methods to supplemental data:
Monetary data¶
- dojo.cldr.monetary.getData(code)
returns an object with currency-specific formatting information. The object has the two properties .places and .round
Parameter Type Description code String an ISO 4217 currency code
dojo.cldr.supplemental¶
- dojo.cldr.supplemental.getFirstDayOfWeek(locale)
Returns a zero-based index for first day of the week, as used by the local (Gregorian) calendar. e.g. Sunday (returns 0), or Monday (returns 1)
Parameter Type Description locale String The locale to assume for loading localized resources in this page, specified according to RFC 3066. Must be specified entirely in lowercase, e.g. en-us and zh-cn. See the documentation for dojo.i18n and dojo.requireLocalization for details on loading localized resources. If no locale is specified, Dojo assumes the browser’s user locale as defined by dojo.locale. - dojo.cldr.supplemental.getWeekend(locale)
Returns a hash containing the start and end days of the weekend.
Parameter Type Description locale String The locale to assume for loading localized resources in this page, specified according to RFC 3066. Must be specified entirely in lowercase, e.g. en-us and zh-cn. See the documentation for dojo.i18n and dojo.requireLocalization for details on loading localized resources. If no locale is specified, Dojo assumes the browser’s user locale as defined by dojo.locale.
Buildscripts in util/buildscripts/cldr¶
The scripts in this directory are responsible for generating the data tables in dojo/cldr/nls. Dojo provides a subset of this output in dojo/cldr/nls under source control, the rest must be generated by the developer using these scripts.
To trigger generation of a full set of locale resources, change into the directory util/buildscripts/cldr and simply type “ant”. An optional list of locales may be specified as an ant property to limit the set of locales built. Currencies may also be specified, but a default list is included in the ant script.
NOTE: it is currently necessary to perform a one-time installation of the Saxon XSLT processor in ~/.ant/lib due to classpath issues and workarounds. The ant task will do this for you. Also, ant version 1.6.5 is recommended. The build script does not properly resolve the XSLT catalog with newer versions of ant which makes the process take much longer. See ticket #7969
Examples¶
Monetary example¶
The following example prints out the monetary data (places and round) for EUR (Euro):
<script type="text/javascript">
dojo.require("dijit.form.Button");
// load monetary data:
dojo.require("dojo.cldr.monetary");
</script>
<button id="monetaryButton" dojoType="dijit.form.Button" type="button">Get Monetary data for EUR (Euro)
<script type="dojo/method" event="onClick">
// the ISO 4217 currency code for Euro:
var iso = 'EUR';
// get monetary data:
var cldrMonetary = dojo.cldr.monetary.getData(iso);
// print out places:
dojo.byId("places").innerHTML = "Places: " + cldrMonetary.places;
// print out round:
dojo.byId("round").innerHTML = "Round: " + cldrMonetary.round;
</script>
</button>
<div id="places"></div>
<div id="round"></div>