Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
if(!dojo._hasResource["dojo.currency"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource["dojo.currency"] = true;
3
dojo.provide("dojo.currency");
4
 
5
dojo.require("dojo.number");
6
dojo.require("dojo.i18n");
7
dojo.requireLocalization("dojo.cldr", "currency", null, "ko,zh,ja,en,en-ca,en-au,ROOT,en-us,it,fr,pt,es,de");
8
dojo.require("dojo.cldr.monetary");
9
 
10
dojo.currency._mixInDefaults = function(options){
11
	options = options || {};
12
	options.type = "currency";
13
 
14
	// Get locale-depenent currency data, like the symbol
15
	var bundle = dojo.i18n.getLocalization("dojo.cldr", "currency", options.locale) || {};
16
 
17
	// Mixin locale-independent currency data, like # of places
18
	var iso = options.currency;
19
	var data = dojo.cldr.monetary.getData(iso);
20
 
21
	dojo.forEach(["displayName","symbol","group","decimal"], function(prop){
22
		data[prop] = bundle[iso+"_"+prop];
23
	});
24
 
25
	data.fractional = [true, false];
26
 
27
	// Mixin with provided options
28
	return dojo.mixin(data, options);
29
}
30
 
31
dojo.currency.format = function(/*Number*/value, /*Object?*/options){
32
// summary:
33
//		Format a Number as a String, using locale-specific settings
34
//
35
// description:
36
//		Create a string from a Number using a known localized pattern.
37
//		Formatting patterns appropriate to the locale are chosen from the CLDR http://unicode.org/cldr
38
//		as well as the appropriate symbols and delimiters.  See http://www.unicode.org/reports/tr35/#Number_Elements
39
//
40
// value:
41
//		the number to be formatted.
42
//
43
// options: object {currency: String, pattern: String?, places: Number?, round: Number?, symbol: String?, locale: String?}
44
//		currency- the ISO4217 currency code, a three letter sequence like "USD"
45
//			See http://en.wikipedia.org/wiki/ISO_4217
46
//		symbol- override currency symbol. Normally, will be looked up in table of supported currencies, and ISO currency code will
47
//			be used if not found.  See dojo.i18n.cldr.nls->currency.js
48
//		pattern- override formatting pattern with this string (see dojo.number.applyPattern)
49
//		places- fixed number of decimal places to show.  Default is defined by the currency.
50
//	    round- 5 rounds to nearest .5; 0 rounds to nearest whole (default). -1 means don't round.
51
//		locale- override the locale used to determine formatting rules
52
 
53
	return dojo.number.format(value, dojo.currency._mixInDefaults(options));
54
}
55
 
56
dojo.currency.regexp = function(/*Object?*/options){
57
//
58
// summary:
59
//		Builds the regular needed to parse a number
60
//
61
// description:
62
//		Returns regular expression with positive and negative match, group and decimal separators
63
//
64
// options: object {pattern: String, locale: String, strict: Boolean, places: mixed}
65
//		currency- the ISO4217 currency code, a three letter sequence like "USD"
66
//			See http://en.wikipedia.org/wiki/ISO_4217
67
//		symbol- override currency symbol. Normally, will be looked up in table of supported currencies, and ISO currency code will
68
//			be used if not found.  See dojo.i18n.cldr.nls->currency.js
69
//		pattern- override pattern with this string
70
//		locale- override the locale used to determine formatting rules
71
//		strict- strict parsing, false by default
72
//		places- number of decimal places to accept.  Default is defined by currency.
73
	return dojo.number.regexp(dojo.currency._mixInDefaults(options)); // String
74
}
75
 
76
dojo.currency.parse = function(/*String*/expression, /*Object?*/options){
77
//
78
// summary:
79
//		Convert a properly formatted string to a primitive Number,
80
//		using locale-specific settings.
81
//
82
// description:
83
//		Create a Number from a string using a known localized pattern.
84
//		Formatting patterns are chosen appropriate to the locale.
85
//		Formatting patterns are implemented using the syntax described at *URL*
86
//
87
// expression: A string representation of a Number
88
//
89
// options: object {pattern: string, locale: string, strict: boolean}
90
//		currency- the ISO4217 currency code, a three letter sequence like "USD"
91
//			See http://en.wikipedia.org/wiki/ISO_4217
92
//		symbol- override currency symbol. Normally, will be looked up in table of supported currencies, and ISO currency code will
93
//			be used if not found.  See dojo.i18n.cldr.nls->currency.js
94
//		pattern- override pattern with this string
95
//		locale- override the locale used to determine formatting rules
96
//		strict- strict parsing, false by default
97
//		places- number of decimal places to accept.  Default is defined by currency.
98
//		fractional- where places are implied by pattern or explicit 'places' parameter, whether to include the fractional portion.
99
//			By default for currencies, it the fractional portion is optional.
100
	return dojo.number.parse(expression, dojo.currency._mixInDefaults(options));
101
}
102
 
103
}