]> git.wh0rd.org - tt-rss.git/blob - lib/dojo/currency.js
upgrade Dojo to 1.6.1
[tt-rss.git] / lib / dojo / currency.js
1 /*
2 Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
3 Available via Academic Free License >= 2.1 OR the modified BSD license.
4 see: http://dojotoolkit.org/license for details
5 */
6
7
8 if(!dojo._hasResource["dojo.currency"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
9 dojo._hasResource["dojo.currency"] = true;
10 dojo.provide("dojo.currency");
11 dojo.require("dojo.number");
12 dojo.require("dojo.i18n");
13 dojo.requireLocalization("dojo.cldr", "currency", null, "ROOT,ar,ca,cs,da,de,el,en,en-au,en-ca,es,fi,fr,he,hu,it,ja,ko,nb,nl,pl,pt,ro,ru,sk,sl,sv,th,tr,zh,zh-hant,zh-hk,zh-tw");
14 dojo.require("dojo.cldr.monetary");
15
16 dojo.getObject("currency", true, dojo);
17
18 /*=====
19 dojo.currency = {
20 // summary: localized formatting and parsing routines for currencies
21 //
22 // description: extends dojo.number to provide culturally-appropriate formatting of values
23 // in various world currencies, including use of a currency symbol. The currencies are specified
24 // by a three-letter international symbol in all uppercase, and support for the currencies is
25 // provided by the data in `dojo.cldr`. The scripts generating dojo.cldr specify which
26 // currency support is included. A fixed number of decimal places is determined based
27 // on the currency type and is not determined by the 'pattern' argument. The fractional
28 // portion is optional, by default, and variable length decimals are not supported.
29 }
30 =====*/
31
32 dojo.currency._mixInDefaults = function(options){
33 options = options || {};
34 options.type = "currency";
35
36 // Get locale-dependent currency data, like the symbol
37 var bundle = dojo.i18n.getLocalization("dojo.cldr", "currency", options.locale) || {};
38
39 // Mixin locale-independent currency data, like # of places
40 var iso = options.currency;
41 var data = dojo.cldr.monetary.getData(iso);
42
43 dojo.forEach(["displayName","symbol","group","decimal"], function(prop){
44 data[prop] = bundle[iso+"_"+prop];
45 });
46
47 data.fractional = [true, false];
48
49 // Mixin with provided options
50 return dojo.mixin(data, options);
51 };
52
53 /*=====
54 dojo.declare("dojo.currency.__FormatOptions", [dojo.number.__FormatOptions], {
55 // type: String?
56 // Should not be set. Value is assumed to be "currency".
57 // symbol: String?
58 // localized currency symbol. The default will be looked up in table of supported currencies in `dojo.cldr`
59 // A [ISO4217](http://en.wikipedia.org/wiki/ISO_4217) currency code will be used if not found.
60 // currency: String?
61 // an [ISO4217](http://en.wikipedia.org/wiki/ISO_4217) currency code, a three letter sequence like "USD".
62 // For use with dojo.currency only.
63 // places: Number?
64 // number of decimal places to show. Default is defined based on which currency is used.
65 type: "",
66 symbol: "",
67 currency: "",
68 places: ""
69 });
70 =====*/
71
72 dojo.currency.format = function(/*Number*/value, /*dojo.currency.__FormatOptions?*/options){
73 // summary:
74 // Format a Number as a currency, using locale-specific settings
75 //
76 // description:
77 // Create a string from a Number using a known, localized pattern.
78 // [Formatting patterns](http://www.unicode.org/reports/tr35/#Number_Elements)
79 // appropriate to the locale are chosen from the [CLDR](http://unicode.org/cldr)
80 // as well as the appropriate symbols and delimiters and number of decimal places.
81 //
82 // value:
83 // the number to be formatted.
84
85 return dojo.number.format(value, dojo.currency._mixInDefaults(options));
86 };
87
88 dojo.currency.regexp = function(/*dojo.number.__RegexpOptions?*/options){
89 //
90 // summary:
91 // Builds the regular needed to parse a currency value
92 //
93 // description:
94 // Returns regular expression with positive and negative match, group and decimal separators
95 // Note: the options.places default, the number of decimal places to accept, is defined by the currency type.
96 return dojo.number.regexp(dojo.currency._mixInDefaults(options)); // String
97 };
98
99 /*=====
100 dojo.declare("dojo.currency.__ParseOptions", [dojo.number.__ParseOptions], {
101 // type: String?
102 // Should not be set. Value is assumed to be currency.
103 // currency: String?
104 // an [ISO4217](http://en.wikipedia.org/wiki/ISO_4217) currency code, a three letter sequence like "USD".
105 // For use with dojo.currency only.
106 // symbol: String?
107 // localized currency symbol. The default will be looked up in table of supported currencies in `dojo.cldr`
108 // A [ISO4217](http://en.wikipedia.org/wiki/ISO_4217) currency code will be used if not found.
109 // places: Number?
110 // fixed number of decimal places to accept. The default is determined based on which currency is used.
111 // fractional: Boolean?|Array?
112 // Whether to include the fractional portion, where the number of decimal places are implied by the currency
113 // or explicit 'places' parameter. The value [true,false] makes the fractional portion optional.
114 // By default for currencies, it the fractional portion is optional.
115 type: "",
116 currency: "",
117 symbol: "",
118 places: "",
119 fractional: ""
120 });
121 =====*/
122
123 dojo.currency.parse = function(/*String*/expression, /*dojo.currency.__ParseOptions?*/options){
124 //
125 // summary:
126 // Convert a properly formatted currency string to a primitive Number,
127 // using locale-specific settings.
128 //
129 // description:
130 // Create a Number from a string using a known, localized pattern.
131 // [Formatting patterns](http://www.unicode.org/reports/tr35/#Number_Format_Patterns)
132 // are chosen appropriate to the locale, as well as the appropriate symbols and delimiters
133 // and number of decimal places.
134 //
135 // expression: A string representation of a currency value
136
137 return dojo.number.parse(expression, dojo.currency._mixInDefaults(options));
138 };
139
140 }