Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
dojo.provide("dojo.i18n.currency");
14
dojo.require("dojo.experimental");
15
dojo.experimental("dojo.i18n.currency");
16
dojo.require("dojo.regexp");
17
dojo.require("dojo.i18n.common");
18
dojo.require("dojo.i18n.number");
19
dojo.require("dojo.lang.common");
20
dojo.i18n.currency.format = function (value, iso, flags, locale) {
21
	flags = (typeof flags == "object") ? flags : {};
22
	var formatData = dojo.i18n.currency._mapToLocalizedFormatData(dojo.i18n.currency.FORMAT_TABLE, iso, locale);
23
	if (typeof flags.places == "undefined") {
24
		flags.places = formatData.places;
25
	}
26
	if (typeof flags.places == "undefined") {
27
		flags.places = 2;
28
	}
29
	flags.signed = false;
30
	var result = dojo.i18n.number.format(value, flags, locale);
31
	var sym = formatData.symbol;
32
	if (formatData.adjSpace == "symbol") {
33
		if (formatData.placement == "after") {
34
			sym = " " + sym;
35
		} else {
36
			sym = sym + " ";
37
		}
38
	}
39
	if (value < 0) {
40
		if (formatData.signPlacement == "before") {
41
			sym = "-" + sym;
42
		} else {
43
			if (formatData.signPlacement == "after") {
44
				sym = sym + "-";
45
			}
46
		}
47
	}
48
	var spc = (formatData.adjSpace == "number") ? " " : "";
49
	if (formatData.placement == "after") {
50
		result = result + spc + sym;
51
	} else {
52
		result = sym + spc + result;
53
	}
54
	if (value < 0) {
55
		if (formatData.signPlacement == "around") {
56
			result = "(" + result + ")";
57
		} else {
58
			if (formatData.signPlacement == "end") {
59
				result = result + "-";
60
			} else {
61
				if (!formatData.signPlacement || formatData.signPlacement == "begin") {
62
					result = "-" + result;
63
				}
64
			}
65
		}
66
	}
67
	return result;
68
};
69
dojo.i18n.currency.parse = function (value, iso, locale, flags) {
70
	if (typeof flags.validate == "undefined") {
71
		flags.validate = true;
72
	}
73
	if (flags.validate && !dojo.i18n.number.isCurrency(value, iso, locale, flags)) {
74
		return Number.NaN;
75
	}
76
	var sign = (value.indexOf("-") != -1);
77
	var abs = abs.replace(/\-/, "");
78
	var formatData = dojo.i18n.currency._mapToLocalizedFormatData(dojo.i18n.currency.FORMAT_TABLE, iso, locale);
79
	abs = abs.replace(new RegExp("\\" + formatData.symbol), "");
80
	var number = dojo.i18n.number.parse(abs, locale, flags);
81
	if (sign) {
82
		number = number * -1;
83
	}
84
	return number;
85
};
86
dojo.i18n.currency.isCurrency = function (value, iso, locale, flags) {
87
	flags = (typeof flags == "object") ? flags : {};
88
	var numberFormatData = dojo.i18n.number._mapToLocalizedFormatData(dojo.i18n.number.FORMAT_TABLE, locale);
89
	if (typeof flags.separator == "undefined") {
90
		flags.separator = numberFormatData[0];
91
	} else {
92
		if (dojo.lang.isArray(flags.separator) && flags.separator.length == 0) {
93
			flags.separator = [numberFormatData[0], ""];
94
		}
95
	}
96
	if (typeof flags.decimal == "undefined") {
97
		flags.decimal = numberFormatData[2];
98
	}
99
	if (typeof flags.groupSize == "undefined") {
100
		flags.groupSize = numberFormatData[3];
101
	}
102
	if (typeof flags.groupSize2 == "undefined") {
103
		flags.groupSize2 = numberFormatData[4];
104
	}
105
	var formatData = dojo.i18n.currency._mapToLocalizedFormatData(dojo.i18n.currency.FORMAT_TABLE, iso, locale);
106
	if (typeof flags.places == "undefined") {
107
		flags.places = formatData.places;
108
	}
109
	if (typeof flags.places == "undefined") {
110
		flags.places = 2;
111
	}
112
	if (typeof flags.symbol == "undefined") {
113
		flags.symbol = formatData.symbol;
114
	} else {
115
		if (dojo.lang.isArray(flags.symbol) && flags.symbol.length == 0) {
116
			flags.symbol = [formatData.symbol, ""];
117
		}
118
	}
119
	if (typeof flags.placement == "undefined") {
120
		flags.placement = formatData.placement;
121
	}
122
	var re = new RegExp("^" + dojo.regexp.currency(flags) + "$");
123
	return re.test(value);
124
};
125
dojo.i18n.currency._mapToLocalizedFormatData = function (table, iso, locale) {
126
	var formatData = dojo.i18n.currency.FORMAT_TABLE[iso];
127
	if (!dojo.lang.isArray(formatData)) {
128
		return formatData;
129
	}
130
	return dojo.i18n.number._mapToLocalizedFormatData(formatData[0], locale);
131
};
132
(function () {
133
	var arabic = {symbol:"\u062c", placement:"after", htmlSymbol:"?"};
134
	var euro = {symbol:"\u20ac", placement:"before", adjSpace:"symbol", htmlSymbol:"&euro;"};
135
	var euroAfter = {symbol:"\u20ac", placement:"after", htmlSymbol:"&euro;"};
136
	dojo.i18n.currency.FORMAT_TABLE = {AED:{symbol:"\u062c", placement:"after"}, ARS:{symbol:"$", signPlacement:"after"}, ATS:{symbol:"\u20ac", adjSpace:"number", signPlacement:"after", htmlSymbol:"&euro;"}, AUD:{symbol:"$"}, BOB:{symbol:"$b"}, BRL:{symbol:"R$", adjSpace:"symbol"}, BEF:euroAfter, BHD:arabic, CAD:[{"*":{symbol:"$"}, "fr-ca":{symbol:"$", placement:"after", signPlacement:"around"}}], CHF:{symbol:"CHF", adjSpace:"symbol", signPlacement:"after"}, CLP:{symbol:"$"}, COP:{symbol:"$", signPlacement:"around"}, CNY:{symbol:"\xa5", htmlSymbol:"&yen;"}, CRC:{symbol:"\u20a1", signPlacement:"after", htmlSymbol:"?"}, CZK:{symbol:"Kc", adjSpace:"symbol", signPlacement:"after"}, DEM:euroAfter, DKK:{symbol:"kr.", adjSpace:"symbol", signPlacement:"after"}, DOP:{symbol:"$"}, DZD:arabic, ECS:{symbol:"$", signPlacement:"after"}, EGP:arabic, ESP:euroAfter, EUR:euro, FIM:euroAfter, FRF:euroAfter, GBP:{symbol:"\xa3", htmlSymbol:"&pound;"}, GRD:{symbol:"\u20ac", signPlacement:"end", htmlSymbol:"&euro;"}, GTQ:{symbol:"Q", signPlacement:"after"}, HKD:{symbol:"HK$"}, HNL:{symbol:"L.", signPlacement:"end"}, HUF:{symbol:"Ft", placement:"after", adjSpace:"symbol"}, IEP:{symbol:"\u20ac", htmlSymbol:"&euro;"}, ILS:{symbol:"\u05e9\"\u05d7", placement:"after", htmlSymbol:"?"}, INR:{symbol:"Rs."}, ITL:{symbol:"\u20ac", signPlacement:"after", htmlSymbol:"&euro;"}, JOD:arabic, JPY:{symbol:"\xa5", places:0, htmlSymbol:"&yen;"}, KRW:{symbol:"\u20a9", places:0, htmlSymbol:"?"}, KWD:arabic, LBP:arabic, LUF:euroAfter, MAD:arabic, MXN:{symbol:"$", signPlacement:"around"}, NIO:{symbol:"C$", adjSpace:"symbol", signPlacement:"after"}, NLG:{symbol:"\u20ac", signPlacement:"end", htmlSymbol:"&euro;"}, NOK:{symbol:"kr", adjSpace:"symbol", signPlacement:"after"}, NZD:{symbol:"$"}, OMR:arabic, PAB:{symbol:"B/", adjSpace:"symbol", signPlacement:"after"}, PEN:{symbol:"S/", signPlacement:"after"}, PLN:{symbol:"z", placement:"after"}, PTE:euroAfter, PYG:{symbol:"Gs.", signPlacement:"after"}, QAR:arabic, RUR:{symbol:"rub.", placement:"after"}, SAR:arabic, SEK:{symbol:"kr", placement:"after", adjSpace:"symbol"}, SGD:{symbol:"$"}, SVC:{symbol:"\u20a1", signPlacement:"after", adjSpace:"symbol"}, SYP:arabic, TND:arabic, TRL:{symbol:"TL", placement:"after"}, TWD:{symbol:"NT$"}, USD:{symbol:"$"}, UYU:{symbol:"$U", signplacement:"after", adjSpace:"symbol"}, VEB:{symbol:"Bs", signplacement:"after", adjSpace:"symbol"}, YER:arabic, ZAR:{symbol:"R", signPlacement:"around"}};
137
})();
138