twitter_cldr_js 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +12 -0
- data/History.txt +3 -0
- data/LICENSE +177 -0
- data/NOTICE +120 -0
- data/README.md +161 -0
- data/Rakefile +66 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_af.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_ar.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_ca.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_cs.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_da.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_de.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_el.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_en.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_es.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_eu.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_fa.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_fi.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_fil.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_fr.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_he.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_hi.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_hu.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_id.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_it.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_ja.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_ko.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_msa.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_nl.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_no.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_pl.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_pt.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_ru.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_sv.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_th.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_tr.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_uk.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_ur.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_zh-cn.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_zh-tw.js +887 -0
- data/lib/twitter_cldr/js/compiler.rb +49 -0
- data/lib/twitter_cldr/js/mustache/bundle.coffee +15 -0
- data/lib/twitter_cldr/js/mustache/calendars/datetime.coffee +240 -0
- data/lib/twitter_cldr/js/mustache/calendars/timespan.coffee +52 -0
- data/lib/twitter_cldr/js/mustache/numbers/numbers.coffee +179 -0
- data/lib/twitter_cldr/js/mustache/plurals/rules.coffee +14 -0
- data/lib/twitter_cldr/js/mustache/shared/currencies.coffee +27 -0
- data/lib/twitter_cldr/js/renderers/base.rb +18 -0
- data/lib/twitter_cldr/js/renderers/bundle.rb +18 -0
- data/lib/twitter_cldr/js/renderers/calendars/datetime_renderer.rb +34 -0
- data/lib/twitter_cldr/js/renderers/calendars/timespan_renderer.rb +39 -0
- data/lib/twitter_cldr/js/renderers/numbers/numbers_renderer.rb +31 -0
- data/lib/twitter_cldr/js/renderers/plurals/rules/plural_rules_compiler.rb +93 -0
- data/lib/twitter_cldr/js/renderers/plurals/rules/plural_rules_renderer.rb +26 -0
- data/lib/twitter_cldr/js/renderers/shared/currencies_renderer.rb +23 -0
- data/lib/twitter_cldr/js/renderers.rb +31 -0
- data/lib/twitter_cldr/js/tasks/tasks.rake +14 -0
- data/lib/twitter_cldr/js/tasks/tasks.rb +88 -0
- data/lib/twitter_cldr/js/version.rb +10 -0
- data/lib/twitter_cldr/js.rb +31 -0
- data/spec/js/calendars/datetime.spec.js +418 -0
- data/spec/js/calendars/timespan.spec.js +91 -0
- data/spec/js/numbers/currency.spec.js +34 -0
- data/spec/js/numbers/decimal.spec.js +24 -0
- data/spec/js/numbers/helpers/fraction.spec.js +23 -0
- data/spec/js/numbers/helpers/integer.spec.js +100 -0
- data/spec/js/numbers/number.spec.js +70 -0
- data/spec/js/numbers/percent.spec.js +22 -0
- data/spec/js/plurals/plural_rules.spec.js +28 -0
- data/spec/ruby/renderers/plurals/plural_rules_compiler_spec.rb +56 -0
- data/spec/ruby/spec_helper.rb +11 -0
- data/twitter_cldr_js.gemspec +34 -0
- metadata +224 -0
@@ -0,0 +1,887 @@
|
|
1
|
+
/*
|
2
|
+
// Copyright 2012 Twitter, Inc
|
3
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
4
|
+
|
5
|
+
// TwitterCLDR (JavaScript) v1.8.0
|
6
|
+
// Authors: Cameron Dutro [@camertron]
|
7
|
+
Kirill Lashuk [@KL_7]
|
8
|
+
portions by Sven Fuchs [@svenfuchs]
|
9
|
+
// Homepage: https://twitter.com
|
10
|
+
// Description: Provides date, time, number, and list formatting functionality for various Twitter-supported locales in Javascript.
|
11
|
+
*/
|
12
|
+
|
13
|
+
var BaseHelper, Currencies, CurrencyFormatter, DateTimeFormatter, DecimalFormatter, FractionHelper, IntegerHelper, NumberFormatter, PercentFormatter, PluralRules, TimespanFormatter, TwitterCldr, key, obj,
|
14
|
+
__hasProp = {}.hasOwnProperty,
|
15
|
+
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
16
|
+
|
17
|
+
TwitterCldr = {};
|
18
|
+
|
19
|
+
TwitterCldr.PluralRules = PluralRules = (function() {
|
20
|
+
|
21
|
+
function PluralRules() {}
|
22
|
+
|
23
|
+
PluralRules.rules = {"keys": ["other"], "rule": function(n) { return "other" }};
|
24
|
+
|
25
|
+
PluralRules.all = function() {
|
26
|
+
return this.rules.keys;
|
27
|
+
};
|
28
|
+
|
29
|
+
PluralRules.rule_for = function(number) {
|
30
|
+
try {
|
31
|
+
return this.rules.rule(number);
|
32
|
+
} catch (error) {
|
33
|
+
return "other";
|
34
|
+
}
|
35
|
+
};
|
36
|
+
|
37
|
+
return PluralRules;
|
38
|
+
|
39
|
+
})();
|
40
|
+
|
41
|
+
TwitterCldr.TimespanFormatter = TimespanFormatter = (function() {
|
42
|
+
|
43
|
+
function TimespanFormatter() {
|
44
|
+
this.default_type = "default";
|
45
|
+
this.tokens = {"ago":{"second":{"default":{"other":[{"value":"{0}","type":"placeholder"},{"value":"秒前","type":"plaintext"}]}},"minute":{"default":{"other":[{"value":"{0}","type":"placeholder"},{"value":"分前","type":"plaintext"}]}},"hour":{"default":{"other":[{"value":"{0}","type":"placeholder"},{"value":"時間前","type":"plaintext"}]}},"day":{"default":{"other":[{"value":"{0}","type":"placeholder"},{"value":"日前","type":"plaintext"}]}},"week":{"default":{"other":[{"value":"{0}","type":"placeholder"},{"value":"週前","type":"plaintext"}]}},"month":{"default":{"other":[{"value":"{0}","type":"placeholder"},{"value":"か月前","type":"plaintext"}]}},"year":{"default":{"other":[{"value":"{0}","type":"placeholder"},{"value":"年前","type":"plaintext"}]}}},"until":{"second":{"default":{"other":[{"value":"{0}","type":"placeholder"},{"value":" 秒後","type":"plaintext"}]}},"minute":{"default":{"other":[{"value":"{0}","type":"placeholder"},{"value":" 分後","type":"plaintext"}]}},"hour":{"default":{"other":[{"value":"{0}","type":"placeholder"},{"value":" 時間後","type":"plaintext"}]}},"day":{"default":{"other":[{"value":"{0}","type":"placeholder"},{"value":" 日後","type":"plaintext"}]}},"week":{"default":{"other":[{"value":"{0}","type":"placeholder"},{"value":" 週間後","type":"plaintext"}]}},"month":{"default":{"other":[{"value":"{0}","type":"placeholder"},{"value":" か月後","type":"plaintext"}]}},"year":{"default":{"other":[{"value":"{0}","type":"placeholder"},{"value":" 年後","type":"plaintext"}]}}},"none":{"second":{"default":{"other":[{"value":"{0}","type":"placeholder"},{"value":"秒","type":"plaintext"}]},"short":{"other":[{"value":"{0}","type":"placeholder"},{"value":"秒","type":"plaintext"}]},"abbreviated":{"other":[{"value":"{0}","type":"placeholder"},{"value":"秒","type":"plaintext"}]}},"minute":{"default":{"other":[{"value":"{0}","type":"placeholder"},{"value":"分","type":"plaintext"}]},"short":{"other":[{"value":"{0}","type":"placeholder"},{"value":"分","type":"plaintext"}]},"abbreviated":{"other":[{"value":"{0}","type":"placeholder"},{"value":"分","type":"plaintext"}]}},"hour":{"default":{"other":[{"value":"{0}","type":"placeholder"},{"value":"時間","type":"plaintext"}]},"short":{"other":[{"value":"{0}","type":"placeholder"},{"value":"時間","type":"plaintext"}]},"abbreviated":{"other":[{"value":"{0}","type":"placeholder"},{"value":"時間","type":"plaintext"}]}},"day":{"default":{"other":[{"value":"{0}","type":"placeholder"},{"value":"日","type":"plaintext"}]},"short":{"other":[{"value":"{0}","type":"placeholder"},{"value":"日","type":"plaintext"}]},"abbreviated":{"other":[{"value":"{0}","type":"placeholder"},{"value":"日","type":"plaintext"}]}},"week":{"default":{"other":[{"value":"{0}","type":"placeholder"},{"value":"週","type":"plaintext"}]},"short":{"other":[{"value":"{0}","type":"placeholder"},{"value":"週","type":"plaintext"}]}},"month":{"default":{"other":[{"value":"{0}","type":"placeholder"},{"value":"か月","type":"plaintext"}]},"short":{"other":[{"value":"{0}","type":"placeholder"},{"value":"か月","type":"plaintext"}]}},"year":{"default":{"other":[{"value":"{0}","type":"placeholder"},{"value":"年","type":"plaintext"}]},"short":{"other":[{"value":"{0}","type":"placeholder"},{"value":"年","type":"plaintext"}]}}}};
|
46
|
+
this.time_in_seconds = {
|
47
|
+
"second": 1,
|
48
|
+
"minute": 60,
|
49
|
+
"hour": 3600,
|
50
|
+
"day": 86400,
|
51
|
+
"week": 604800,
|
52
|
+
"month": 2629743.83,
|
53
|
+
"year": 31556926
|
54
|
+
};
|
55
|
+
}
|
56
|
+
|
57
|
+
TimespanFormatter.prototype.format = function(seconds, options) {
|
58
|
+
var number, strings, token;
|
59
|
+
if (options == null) {
|
60
|
+
options = {};
|
61
|
+
}
|
62
|
+
options["direction"] || (options["direction"] = (seconds < 0 ? "ago" : "until"));
|
63
|
+
if (options["unit"] === null || options["unit"] === void 0) {
|
64
|
+
options["unit"] = this.calculate_unit(Math.abs(seconds));
|
65
|
+
}
|
66
|
+
options["type"] || (options["type"] = this.default_type);
|
67
|
+
options["number"] = this.calculate_time(Math.abs(seconds), options["unit"]);
|
68
|
+
number = this.calculate_time(Math.abs(seconds), options["unit"]);
|
69
|
+
options["rule"] = TwitterCldr.PluralRules.rule_for(number);
|
70
|
+
strings = (function() {
|
71
|
+
var _i, _len, _ref, _results;
|
72
|
+
_ref = this.tokens[options["direction"]][options["unit"]][options["type"]][options["rule"]];
|
73
|
+
_results = [];
|
74
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
75
|
+
token = _ref[_i];
|
76
|
+
_results.push(token.value);
|
77
|
+
}
|
78
|
+
return _results;
|
79
|
+
}).call(this);
|
80
|
+
return strings.join("").replace(/\{[0-9]\}/, number.toString());
|
81
|
+
};
|
82
|
+
|
83
|
+
TimespanFormatter.prototype.calculate_unit = function(seconds) {
|
84
|
+
if (seconds < 30) {
|
85
|
+
return "second";
|
86
|
+
} else if (seconds < 2670) {
|
87
|
+
return "minute";
|
88
|
+
} else if (seconds < 86369) {
|
89
|
+
return "hour";
|
90
|
+
} else if (seconds < 604800) {
|
91
|
+
return "day";
|
92
|
+
} else if (seconds < 2591969) {
|
93
|
+
return "week";
|
94
|
+
} else if (seconds < 31556926) {
|
95
|
+
return "month";
|
96
|
+
} else {
|
97
|
+
return "year";
|
98
|
+
}
|
99
|
+
};
|
100
|
+
|
101
|
+
TimespanFormatter.prototype.calculate_time = function(seconds, unit) {
|
102
|
+
return Math.round(seconds / this.time_in_seconds[unit]);
|
103
|
+
};
|
104
|
+
|
105
|
+
return TimespanFormatter;
|
106
|
+
|
107
|
+
})();
|
108
|
+
|
109
|
+
TwitterCldr.DateTimeFormatter = DateTimeFormatter = (function() {
|
110
|
+
|
111
|
+
function DateTimeFormatter() {
|
112
|
+
this.tokens = {"date_time":{"default":[{"value":"yyyy","type":"pattern"},{"value":"/","type":"plaintext"},{"value":"MM","type":"pattern"},{"value":"/","type":"plaintext"},{"value":"dd","type":"pattern"},{"value":" ","type":"plaintext"},{"value":"H","type":"pattern"},{"value":":","type":"plaintext"},{"value":"mm","type":"pattern"},{"value":":","type":"plaintext"},{"value":"ss","type":"pattern"}],"full":[{"value":"y","type":"pattern"},{"value":"年","type":"plaintext"},{"value":"M","type":"pattern"},{"value":"月","type":"plaintext"},{"value":"d","type":"pattern"},{"value":"日","type":"plaintext"},{"value":"EEEE","type":"pattern"},{"value":" ","type":"plaintext"},{"value":"H","type":"pattern"},{"value":"時","type":"plaintext"},{"value":"mm","type":"pattern"},{"value":"分","type":"plaintext"},{"value":"ss","type":"pattern"},{"value":"秒 ","type":"plaintext"},{"value":"zzzz","type":"pattern"}],"long":[{"value":"y","type":"pattern"},{"value":"年","type":"plaintext"},{"value":"M","type":"pattern"},{"value":"月","type":"plaintext"},{"value":"d","type":"pattern"},{"value":"日","type":"plaintext"},{"value":" ","type":"plaintext"},{"value":"H","type":"pattern"},{"value":":","type":"plaintext"},{"value":"mm","type":"pattern"},{"value":":","type":"plaintext"},{"value":"ss","type":"pattern"},{"value":" ","type":"plaintext"},{"value":"z","type":"pattern"}],"medium":[{"value":"yyyy","type":"pattern"},{"value":"/","type":"plaintext"},{"value":"MM","type":"pattern"},{"value":"/","type":"plaintext"},{"value":"dd","type":"pattern"},{"value":" ","type":"plaintext"},{"value":"H","type":"pattern"},{"value":":","type":"plaintext"},{"value":"mm","type":"pattern"},{"value":":","type":"plaintext"},{"value":"ss","type":"pattern"}],"short":[{"value":"yyyy","type":"pattern"},{"value":"/","type":"plaintext"},{"value":"MM","type":"pattern"},{"value":"/","type":"plaintext"},{"value":"dd","type":"pattern"},{"value":" ","type":"plaintext"},{"value":"H","type":"pattern"},{"value":":","type":"plaintext"},{"value":"mm","type":"pattern"}]},"time":{"default":[{"value":"H","type":"pattern"},{"value":":","type":"plaintext"},{"value":"mm","type":"pattern"},{"value":":","type":"plaintext"},{"value":"ss","type":"pattern"}],"full":[{"value":"H","type":"pattern"},{"value":"時","type":"plaintext"},{"value":"mm","type":"pattern"},{"value":"分","type":"plaintext"},{"value":"ss","type":"pattern"},{"value":"秒 ","type":"plaintext"},{"value":"zzzz","type":"pattern"}],"long":[{"value":"H","type":"pattern"},{"value":":","type":"plaintext"},{"value":"mm","type":"pattern"},{"value":":","type":"plaintext"},{"value":"ss","type":"pattern"},{"value":" ","type":"plaintext"},{"value":"z","type":"pattern"}],"medium":[{"value":"H","type":"pattern"},{"value":":","type":"plaintext"},{"value":"mm","type":"pattern"},{"value":":","type":"plaintext"},{"value":"ss","type":"pattern"}],"short":[{"value":"H","type":"pattern"},{"value":":","type":"plaintext"},{"value":"mm","type":"pattern"}]},"date":{"default":[{"value":"yyyy","type":"pattern"},{"value":"/","type":"plaintext"},{"value":"MM","type":"pattern"},{"value":"/","type":"plaintext"},{"value":"dd","type":"pattern"}],"full":[{"value":"y","type":"pattern"},{"value":"年","type":"plaintext"},{"value":"M","type":"pattern"},{"value":"月","type":"plaintext"},{"value":"d","type":"pattern"},{"value":"日","type":"plaintext"},{"value":"EEEE","type":"pattern"}],"long":[{"value":"y","type":"pattern"},{"value":"年","type":"plaintext"},{"value":"M","type":"pattern"},{"value":"月","type":"plaintext"},{"value":"d","type":"pattern"},{"value":"日","type":"plaintext"}],"medium":[{"value":"yyyy","type":"pattern"},{"value":"/","type":"plaintext"},{"value":"MM","type":"pattern"},{"value":"/","type":"plaintext"},{"value":"dd","type":"pattern"}],"short":[{"value":"yyyy","type":"pattern"},{"value":"/","type":"plaintext"},{"value":"MM","type":"pattern"},{"value":"/","type":"plaintext"},{"value":"dd","type":"pattern"}]}};
|
113
|
+
this.calendar = {"days":{"format":{"abbreviated":{"fri":"金","mon":"月","sat":"土","sun":"日","thu":"木","tue":"火","wed":"水"},"narrow":{"fri":"金","mon":"月","sat":"土","sun":"日","thu":"木","tue":"火","wed":"水"},"wide":{"fri":"金曜日","mon":"月曜日","sat":"土曜日","sun":"日曜日","thu":"木曜日","tue":"火曜日","wed":"水曜日"}},"stand-alone":{"abbreviated":{"fri":"金","mon":"月","sat":"土","sun":"日","thu":"木","tue":"火","wed":"水"},"narrow":{"fri":"金","mon":"月","sat":"土","sun":"日","thu":"木","tue":"火","wed":"水"},"wide":{"fri":"金曜日","mon":"月曜日","sat":"土曜日","sun":"日曜日","thu":"木曜日","tue":"火曜日","wed":"水曜日"}}},"eras":{"abbr":{"0":"BC","1":"AD"},"name":{"0":"紀元前","1":"西暦"},"narrow":{"0":""}},"fields":{"day":"日","dayperiod":"午前/午後","era":"時代","hour":"時","minute":"分","month":"月","second":"秒","week":"週","weekday":"曜日","year":"年","zone":"タイムゾーン"},"formats":{"date":{"default":{"pattern":"yyyy/MM/dd"},"full":{"pattern":"y年M月d日EEEE"},"long":{"pattern":"y年M月d日"},"medium":{"pattern":"yyyy/MM/dd"},"short":{"pattern":"yyyy/MM/dd"}},"datetime":{"default":{"pattern":"{{date}} {{time}}"},"full":{"pattern":"{{date}} {{time}}"},"long":{"pattern":"{{date}} {{time}}"},"medium":{"pattern":"{{date}} {{time}}"},"short":{"pattern":"{{date}} {{time}}"}},"time":{"default":{"pattern":"H:mm:ss"},"full":{"pattern":"H時mm分ss秒 zzzz"},"long":{"pattern":"H:mm:ss z"},"medium":{"pattern":"H:mm:ss"},"short":{"pattern":"H:mm"}}},"months":{"format":{"abbreviated":{"1":"1月","10":"10月","11":"11月","12":"12月","2":"2月","3":"3月","4":"4月","5":"5月","6":"6月","7":"7月","8":"8月","9":"9月"},"narrow":{"1":1,"10":10,"11":11,"12":12,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9},"wide":{"1":"1月","10":"10月","11":"11月","12":"12月","2":"2月","3":"3月","4":"4月","5":"5月","6":"6月","7":"7月","8":"8月","9":"9月"}},"stand-alone":{"abbreviated":{"1":"1月","10":"10月","11":"11月","12":"12月","2":"2月","3":"3月","4":"4月","5":"5月","6":"6月","7":"7月","8":"8月","9":"9月"},"narrow":{"1":1,"10":10,"11":11,"12":12,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9},"wide":{"1":"1月","10":"10月","11":"11月","12":"12月","2":"2月","3":"3月","4":"4月","5":"5月","6":"6月","7":"7月","8":"8月","9":"9月"}}},"periods":{"format":{"abbreviated":null,"narrow":null,"wide":{"am":"午前","noon":"正午","pm":"午後"}},"stand-alone":{}},"quarters":{"format":{"abbreviated":{"1":"Q1","2":"Q2","3":"Q3","4":"Q4"},"narrow":{"1":1,"2":2,"3":3,"4":4},"wide":{"1":"第1四半期","2":"第2四半期","3":"第3四半期","4":"第4四半期"}},"stand-alone":{"abbreviated":{"1":"Q1","2":"Q2","3":"Q3","4":"Q4"},"narrow":{"1":1,"2":2,"3":3,"4":4},"wide":{"1":"第1四半期","2":"第2四半期","3":"第3四半期","4":"第4四半期"}}}};
|
114
|
+
this.weekday_keys = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
|
115
|
+
this.methods = {
|
116
|
+
'G': 'era',
|
117
|
+
'y': 'year',
|
118
|
+
'Y': 'year_of_week_of_year',
|
119
|
+
'Q': 'quarter',
|
120
|
+
'q': 'quarter_stand_alone',
|
121
|
+
'M': 'month',
|
122
|
+
'L': 'month_stand_alone',
|
123
|
+
'w': 'week_of_year',
|
124
|
+
'W': 'week_of_month',
|
125
|
+
'd': 'day',
|
126
|
+
'D': 'day_of_month',
|
127
|
+
'F': 'day_of_week_in_month',
|
128
|
+
'E': 'weekday',
|
129
|
+
'e': 'weekday_local',
|
130
|
+
'c': 'weekday_local_stand_alone',
|
131
|
+
'a': 'period',
|
132
|
+
'h': 'hour',
|
133
|
+
'H': 'hour',
|
134
|
+
'K': 'hour',
|
135
|
+
'k': 'hour',
|
136
|
+
'm': 'minute',
|
137
|
+
's': 'second',
|
138
|
+
'S': 'second_fraction',
|
139
|
+
'z': 'timezone',
|
140
|
+
'Z': 'timezone',
|
141
|
+
'v': 'timezone_generic_non_location',
|
142
|
+
'V': 'timezone_metazone'
|
143
|
+
};
|
144
|
+
}
|
145
|
+
|
146
|
+
DateTimeFormatter.prototype.format = function(obj, options) {
|
147
|
+
var format_token, token, tokens,
|
148
|
+
_this = this;
|
149
|
+
format_token = function(token) {
|
150
|
+
var result;
|
151
|
+
result = "";
|
152
|
+
switch (token.type) {
|
153
|
+
case "pattern":
|
154
|
+
return _this.result_for_token(token, obj);
|
155
|
+
default:
|
156
|
+
if (token.value.length > 0 && token.value[0] === "'" && token.value[token.value.length - 1] === "'") {
|
157
|
+
return token.value.substring(1, token.value.length - 1);
|
158
|
+
} else {
|
159
|
+
return token.value;
|
160
|
+
}
|
161
|
+
}
|
162
|
+
};
|
163
|
+
tokens = this.get_tokens(obj, options);
|
164
|
+
return ((function() {
|
165
|
+
var _i, _len, _results;
|
166
|
+
_results = [];
|
167
|
+
for (_i = 0, _len = tokens.length; _i < _len; _i++) {
|
168
|
+
token = tokens[_i];
|
169
|
+
_results.push(format_token(token));
|
170
|
+
}
|
171
|
+
return _results;
|
172
|
+
})()).join("");
|
173
|
+
};
|
174
|
+
|
175
|
+
DateTimeFormatter.prototype.get_tokens = function(obj, options) {
|
176
|
+
return this.tokens[options.format || "date_time"][options.type || "default"];
|
177
|
+
};
|
178
|
+
|
179
|
+
DateTimeFormatter.prototype.result_for_token = function(token, date) {
|
180
|
+
return this[this.methods[token.value[0]]](date, token.value, token.value.length);
|
181
|
+
};
|
182
|
+
|
183
|
+
DateTimeFormatter.prototype.era = function(date, pattern, length) {
|
184
|
+
var choices, index;
|
185
|
+
switch (length) {
|
186
|
+
case 1:
|
187
|
+
case 2:
|
188
|
+
case 3:
|
189
|
+
choices = this.calendar["eras"]["abbr"];
|
190
|
+
break;
|
191
|
+
default:
|
192
|
+
choices = this.calendar["eras"]["name"];
|
193
|
+
}
|
194
|
+
index = date.getFullYear() < 0 ? 0 : 1;
|
195
|
+
return choices[index];
|
196
|
+
};
|
197
|
+
|
198
|
+
DateTimeFormatter.prototype.year = function(date, pattern, length) {
|
199
|
+
var year;
|
200
|
+
year = date.getFullYear().toString();
|
201
|
+
if (length === 2) {
|
202
|
+
if (year.length !== 1) {
|
203
|
+
year = year.slice(-2);
|
204
|
+
}
|
205
|
+
}
|
206
|
+
if (length > 1) {
|
207
|
+
year = ("0000" + year).slice(-length);
|
208
|
+
}
|
209
|
+
return year;
|
210
|
+
};
|
211
|
+
|
212
|
+
DateTimeFormatter.prototype.year_of_week_of_year = function(date, pattern, length) {
|
213
|
+
throw 'not implemented';
|
214
|
+
};
|
215
|
+
|
216
|
+
DateTimeFormatter.prototype.day_of_week_in_month = function(date, pattern, length) {
|
217
|
+
throw 'not implemented';
|
218
|
+
};
|
219
|
+
|
220
|
+
DateTimeFormatter.prototype.quarter = function(date, pattern, length) {
|
221
|
+
var quarter;
|
222
|
+
quarter = ((date.getMonth() / 3) | 0) + 1;
|
223
|
+
switch (length) {
|
224
|
+
case 1:
|
225
|
+
return quarter.toString();
|
226
|
+
case 2:
|
227
|
+
return ("0000" + quarter.toString()).slice(-length);
|
228
|
+
case 3:
|
229
|
+
return this.calendar.quarters.format.abbreviated[quarter];
|
230
|
+
case 4:
|
231
|
+
return this.calendar.quarters.format.wide[quarter];
|
232
|
+
}
|
233
|
+
};
|
234
|
+
|
235
|
+
DateTimeFormatter.prototype.quarter_stand_alone = function(date, pattern, length) {
|
236
|
+
var quarter;
|
237
|
+
quarter = (date.getMonth() - 1) / 3 + 1;
|
238
|
+
switch (length) {
|
239
|
+
case 1:
|
240
|
+
return quarter.toString();
|
241
|
+
case 2:
|
242
|
+
return ("0000" + quarter.toString()).slice(-length);
|
243
|
+
case 3:
|
244
|
+
throw 'not yet implemented (requires cldr\'s "multiple inheritance")';
|
245
|
+
break;
|
246
|
+
case 4:
|
247
|
+
throw 'not yet implemented (requires cldr\'s "multiple inheritance")';
|
248
|
+
break;
|
249
|
+
case 5:
|
250
|
+
return this.calendar.quarters['stand-alone'].narrow[quarter];
|
251
|
+
}
|
252
|
+
};
|
253
|
+
|
254
|
+
DateTimeFormatter.prototype.month = function(date, pattern, length) {
|
255
|
+
var month_str;
|
256
|
+
month_str = (date.getMonth() + 1).toString();
|
257
|
+
switch (length) {
|
258
|
+
case 1:
|
259
|
+
return month_str;
|
260
|
+
case 2:
|
261
|
+
return ("0000" + month_str).slice(-length);
|
262
|
+
case 3:
|
263
|
+
return this.calendar.months.format.abbreviated[month_str];
|
264
|
+
case 4:
|
265
|
+
return this.calendar.months.format.wide[month_str];
|
266
|
+
case 5:
|
267
|
+
throw 'not yet implemented (requires cldr\'s "multiple inheritance")';
|
268
|
+
break;
|
269
|
+
default:
|
270
|
+
throw "Unknown date format";
|
271
|
+
}
|
272
|
+
};
|
273
|
+
|
274
|
+
DateTimeFormatter.prototype.month_stand_alone = function(date, pattern, length) {
|
275
|
+
switch (length) {
|
276
|
+
case 1:
|
277
|
+
return date.getMonth().toString();
|
278
|
+
case 2:
|
279
|
+
return ("0000" + date.getMonth().toString()).slice(-length);
|
280
|
+
case 3:
|
281
|
+
throw 'not yet implemented (requires cldr\'s "multiple inheritance")';
|
282
|
+
break;
|
283
|
+
case 4:
|
284
|
+
throw 'not yet implemented (requires cldr\'s "multiple inheritance")';
|
285
|
+
break;
|
286
|
+
case 5:
|
287
|
+
return this.calendar.months['stand-alone'].narrow[date.month];
|
288
|
+
default:
|
289
|
+
throw "Unknown date format";
|
290
|
+
}
|
291
|
+
};
|
292
|
+
|
293
|
+
DateTimeFormatter.prototype.day = function(date, pattern, length) {
|
294
|
+
switch (length) {
|
295
|
+
case 1:
|
296
|
+
return date.getDate().toString();
|
297
|
+
case 2:
|
298
|
+
return ("0000" + date.getDate().toString()).slice(-length);
|
299
|
+
}
|
300
|
+
};
|
301
|
+
|
302
|
+
DateTimeFormatter.prototype.weekday = function(date, pattern, length) {
|
303
|
+
var key;
|
304
|
+
key = this.weekday_keys[date.getDay()];
|
305
|
+
switch (length) {
|
306
|
+
case 1:
|
307
|
+
case 2:
|
308
|
+
case 3:
|
309
|
+
return this.calendar.days.format.abbreviated[key];
|
310
|
+
case 4:
|
311
|
+
return this.calendar.days.format.wide[key];
|
312
|
+
case 5:
|
313
|
+
return this.calendar.days['stand-alone'].narrow[key];
|
314
|
+
}
|
315
|
+
};
|
316
|
+
|
317
|
+
DateTimeFormatter.prototype.weekday_local = function(date, pattern, length) {
|
318
|
+
var day;
|
319
|
+
switch (length) {
|
320
|
+
case 1:
|
321
|
+
case 2:
|
322
|
+
day = date.getDay();
|
323
|
+
return (day === 0 ? "7" : day.toString());
|
324
|
+
default:
|
325
|
+
return this.weekday(date, pattern, length);
|
326
|
+
}
|
327
|
+
};
|
328
|
+
|
329
|
+
DateTimeFormatter.prototype.weekday_local_stand_alone = function(date, pattern, length) {
|
330
|
+
switch (length) {
|
331
|
+
case 1:
|
332
|
+
return this.weekday_local(date, pattern, length);
|
333
|
+
default:
|
334
|
+
return this.weekday(date, pattern, length);
|
335
|
+
}
|
336
|
+
};
|
337
|
+
|
338
|
+
DateTimeFormatter.prototype.period = function(time, pattern, length) {
|
339
|
+
if (time.getHours() > 11) {
|
340
|
+
return this.calendar.periods.format.wide["pm"];
|
341
|
+
} else {
|
342
|
+
return this.calendar.periods.format.wide["am"];
|
343
|
+
}
|
344
|
+
};
|
345
|
+
|
346
|
+
DateTimeFormatter.prototype.hour = function(time, pattern, length) {
|
347
|
+
var hour;
|
348
|
+
hour = time.getHours();
|
349
|
+
switch (pattern[0]) {
|
350
|
+
case 'h':
|
351
|
+
if (hour > 12) {
|
352
|
+
hour = hour - 12;
|
353
|
+
} else if (hour === 0) {
|
354
|
+
hour = 12;
|
355
|
+
}
|
356
|
+
break;
|
357
|
+
case 'K':
|
358
|
+
if (hour > 11) {
|
359
|
+
hour = hour - 12;
|
360
|
+
}
|
361
|
+
break;
|
362
|
+
case 'k':
|
363
|
+
if (hour === 0) {
|
364
|
+
hour = 24;
|
365
|
+
}
|
366
|
+
}
|
367
|
+
if (length === 1) {
|
368
|
+
return hour.toString();
|
369
|
+
} else {
|
370
|
+
return ("000000" + hour.toString()).slice(-length);
|
371
|
+
}
|
372
|
+
};
|
373
|
+
|
374
|
+
DateTimeFormatter.prototype.minute = function(time, pattern, length) {
|
375
|
+
if (length === 1) {
|
376
|
+
return time.getMinutes().toString();
|
377
|
+
} else {
|
378
|
+
return ("000000" + time.getMinutes().toString()).slice(-length);
|
379
|
+
}
|
380
|
+
};
|
381
|
+
|
382
|
+
DateTimeFormatter.prototype.second = function(time, pattern, length) {
|
383
|
+
if (length === 1) {
|
384
|
+
return time.getSeconds().toString();
|
385
|
+
} else {
|
386
|
+
return ("000000" + time.getSeconds().toString()).slice(-length);
|
387
|
+
}
|
388
|
+
};
|
389
|
+
|
390
|
+
DateTimeFormatter.prototype.second_fraction = function(time, pattern, length) {
|
391
|
+
if (length > 6) {
|
392
|
+
throw 'can not use the S format with more than 6 digits';
|
393
|
+
}
|
394
|
+
return ("000000" + Math.round(Math.pow(time.getMilliseconds() * 100.0, 6 - length)).toString()).slice(-length);
|
395
|
+
};
|
396
|
+
|
397
|
+
DateTimeFormatter.prototype.timezone = function(time, pattern, length) {
|
398
|
+
var hours, minutes;
|
399
|
+
hours = ("00" + (time.getTimezoneOffset() / 60).toString()).slice(-2);
|
400
|
+
minutes = ("00" + (time.getTimezoneOffset() % 60).toString()).slice(-2);
|
401
|
+
switch (length) {
|
402
|
+
case 1:
|
403
|
+
case 2:
|
404
|
+
case 3:
|
405
|
+
return "-" + hours + ":" + minutes;
|
406
|
+
default:
|
407
|
+
return "UTC -" + hours + ":" + minutes;
|
408
|
+
}
|
409
|
+
};
|
410
|
+
|
411
|
+
DateTimeFormatter.prototype.timezone_generic_non_location = function(time, pattern, length) {
|
412
|
+
throw 'not yet implemented (requires timezone translation data")';
|
413
|
+
};
|
414
|
+
|
415
|
+
return DateTimeFormatter;
|
416
|
+
|
417
|
+
})();
|
418
|
+
|
419
|
+
TwitterCldr.NumberFormatter = NumberFormatter = (function() {
|
420
|
+
|
421
|
+
function NumberFormatter() {
|
422
|
+
this.all_tokens = {"decimal":{"positive":["","#,##0.###"],"negative":["-","#,##0.###"]},"percent":{"positive":["","#,##0","%"],"negative":["-","#,##0","%"]},"currency":{"positive":["¤","#,##0.00"],"negative":["-¤","#,##0.00"]}};
|
423
|
+
this.tokens = [];
|
424
|
+
this.symbols = {"alias":"","decimal":".","exponential":"E","group":",","infinity":"∞","list":";","minus_sign":"-","nan":"NaN(非数)","per_mille":"‰","percent_sign":"%","plus_sign":"+"};
|
425
|
+
this.default_symbols = {
|
426
|
+
'group': ',',
|
427
|
+
'decimal': '.',
|
428
|
+
'plus_sign': '+',
|
429
|
+
'minus_sign': '-'
|
430
|
+
};
|
431
|
+
}
|
432
|
+
|
433
|
+
NumberFormatter.prototype.format = function(number, options) {
|
434
|
+
var fraction, fraction_format, int, integer_format, key, opts, prefix, result, sign, suffix, val, _ref, _ref1;
|
435
|
+
if (options == null) {
|
436
|
+
options = {};
|
437
|
+
}
|
438
|
+
opts = this.default_format_options_for(number);
|
439
|
+
for (key in options) {
|
440
|
+
val = options[key];
|
441
|
+
opts[key] = options[key] != null ? options[key] : opts[key];
|
442
|
+
}
|
443
|
+
_ref = this.partition_tokens(this.get_tokens(number, opts)), prefix = _ref[0], suffix = _ref[1], integer_format = _ref[2], fraction_format = _ref[3];
|
444
|
+
_ref1 = this.parse_number(number, opts), int = _ref1[0], fraction = _ref1[1];
|
445
|
+
result = integer_format.apply(parseFloat(int), opts);
|
446
|
+
if (fraction) {
|
447
|
+
result += fraction_format.apply(fraction, opts);
|
448
|
+
}
|
449
|
+
sign = number < 0 && prefix !== "-" ? this.symbols.minus_sign || this.default_symbols.minus_sign : "";
|
450
|
+
return "" + prefix + result + suffix;
|
451
|
+
};
|
452
|
+
|
453
|
+
NumberFormatter.prototype.partition_tokens = function(tokens) {
|
454
|
+
return [tokens[0] || "", tokens[2] || "", new IntegerHelper(tokens[1], this.symbols), new FractionHelper(tokens[1], this.symbols)];
|
455
|
+
};
|
456
|
+
|
457
|
+
NumberFormatter.prototype.parse_number = function(number, options) {
|
458
|
+
var precision;
|
459
|
+
if (options == null) {
|
460
|
+
options = {};
|
461
|
+
}
|
462
|
+
if (options.precision != null) {
|
463
|
+
precision = options.precision;
|
464
|
+
} else {
|
465
|
+
precision = this.precision_from(number);
|
466
|
+
}
|
467
|
+
number = this.round_to(number, precision);
|
468
|
+
return Math.abs(number).toFixed(precision).split(".");
|
469
|
+
};
|
470
|
+
|
471
|
+
NumberFormatter.prototype.precision_from = function(num) {
|
472
|
+
var parts;
|
473
|
+
parts = num.toString().split(".");
|
474
|
+
if (parts.length === 2) {
|
475
|
+
return parts[1].length;
|
476
|
+
} else {
|
477
|
+
return 0;
|
478
|
+
}
|
479
|
+
};
|
480
|
+
|
481
|
+
NumberFormatter.prototype.round_to = function(number, precision) {
|
482
|
+
var factor;
|
483
|
+
factor = Math.pow(10, precision);
|
484
|
+
return Math.round(number * factor) / factor;
|
485
|
+
};
|
486
|
+
|
487
|
+
NumberFormatter.prototype.get_tokens = function() {
|
488
|
+
throw "get_tokens() not implemented - use a derived class like PercentFormatter.";
|
489
|
+
};
|
490
|
+
|
491
|
+
return NumberFormatter;
|
492
|
+
|
493
|
+
})();
|
494
|
+
|
495
|
+
TwitterCldr.PercentFormatter = PercentFormatter = (function(_super) {
|
496
|
+
|
497
|
+
__extends(PercentFormatter, _super);
|
498
|
+
|
499
|
+
function PercentFormatter(options) {
|
500
|
+
if (options == null) {
|
501
|
+
options = {};
|
502
|
+
}
|
503
|
+
this.default_percent_sign = "%";
|
504
|
+
PercentFormatter.__super__.constructor.apply(this, arguments);
|
505
|
+
}
|
506
|
+
|
507
|
+
PercentFormatter.prototype.format = function(number, options) {
|
508
|
+
if (options == null) {
|
509
|
+
options = {};
|
510
|
+
}
|
511
|
+
return PercentFormatter.__super__.format.call(this, number, options).replace('¤', this.symbols.percent_sign || this.default_percent_sign);
|
512
|
+
};
|
513
|
+
|
514
|
+
PercentFormatter.prototype.default_format_options_for = function(number) {
|
515
|
+
return {
|
516
|
+
precision: 0
|
517
|
+
};
|
518
|
+
};
|
519
|
+
|
520
|
+
PercentFormatter.prototype.get_tokens = function(number, options) {
|
521
|
+
if (number < 0) {
|
522
|
+
return this.all_tokens.percent.negative;
|
523
|
+
} else {
|
524
|
+
return this.all_tokens.percent.positive;
|
525
|
+
}
|
526
|
+
};
|
527
|
+
|
528
|
+
return PercentFormatter;
|
529
|
+
|
530
|
+
})(NumberFormatter);
|
531
|
+
|
532
|
+
TwitterCldr.DecimalFormatter = DecimalFormatter = (function(_super) {
|
533
|
+
|
534
|
+
__extends(DecimalFormatter, _super);
|
535
|
+
|
536
|
+
function DecimalFormatter() {
|
537
|
+
return DecimalFormatter.__super__.constructor.apply(this, arguments);
|
538
|
+
}
|
539
|
+
|
540
|
+
DecimalFormatter.prototype.format = function(number, options) {
|
541
|
+
if (options == null) {
|
542
|
+
options = {};
|
543
|
+
}
|
544
|
+
try {
|
545
|
+
return DecimalFormatter.__super__.format.call(this, number, options);
|
546
|
+
} catch (error) {
|
547
|
+
return number;
|
548
|
+
}
|
549
|
+
};
|
550
|
+
|
551
|
+
DecimalFormatter.prototype.default_format_options_for = function(number) {
|
552
|
+
return {
|
553
|
+
precision: this.precision_from(number)
|
554
|
+
};
|
555
|
+
};
|
556
|
+
|
557
|
+
DecimalFormatter.prototype.get_tokens = function(number, options) {
|
558
|
+
if (options == null) {
|
559
|
+
options = {};
|
560
|
+
}
|
561
|
+
if (number < 0) {
|
562
|
+
return this.all_tokens.decimal.negative;
|
563
|
+
} else {
|
564
|
+
return this.all_tokens.decimal.positive;
|
565
|
+
}
|
566
|
+
};
|
567
|
+
|
568
|
+
return DecimalFormatter;
|
569
|
+
|
570
|
+
})(NumberFormatter);
|
571
|
+
|
572
|
+
TwitterCldr.CurrencyFormatter = CurrencyFormatter = (function(_super) {
|
573
|
+
|
574
|
+
__extends(CurrencyFormatter, _super);
|
575
|
+
|
576
|
+
function CurrencyFormatter(options) {
|
577
|
+
if (options == null) {
|
578
|
+
options = {};
|
579
|
+
}
|
580
|
+
this.default_currency_symbol = "$";
|
581
|
+
this.default_precision = 2;
|
582
|
+
CurrencyFormatter.__super__.constructor.apply(this, arguments);
|
583
|
+
}
|
584
|
+
|
585
|
+
CurrencyFormatter.prototype.format = function(number, options) {
|
586
|
+
var currency;
|
587
|
+
if (options == null) {
|
588
|
+
options = {};
|
589
|
+
}
|
590
|
+
if (options.currency) {
|
591
|
+
if (TwitterCldr.Currencies != null) {
|
592
|
+
currency = TwitterCldr.Currencies.for_code(options.currency);
|
593
|
+
currency || (currency = TwitterCldr.Currencies.for_country(options.currency));
|
594
|
+
currency || (currency = {
|
595
|
+
symbol: options.currency
|
596
|
+
});
|
597
|
+
} else {
|
598
|
+
currency = {
|
599
|
+
symbol: options.currency
|
600
|
+
};
|
601
|
+
}
|
602
|
+
} else {
|
603
|
+
currency = {
|
604
|
+
symbol: this.default_currency_symbol
|
605
|
+
};
|
606
|
+
}
|
607
|
+
return CurrencyFormatter.__super__.format.call(this, number, options).replace('¤', currency.symbol);
|
608
|
+
};
|
609
|
+
|
610
|
+
CurrencyFormatter.prototype.default_format_options_for = function(number) {
|
611
|
+
var precision;
|
612
|
+
precision = this.precision_from(number);
|
613
|
+
if (precision === 0) {
|
614
|
+
precision = this.default_precision;
|
615
|
+
}
|
616
|
+
return {
|
617
|
+
precision: precision
|
618
|
+
};
|
619
|
+
};
|
620
|
+
|
621
|
+
CurrencyFormatter.prototype.get_tokens = function(number, options) {
|
622
|
+
if (options == null) {
|
623
|
+
options = {};
|
624
|
+
}
|
625
|
+
if (number < 0) {
|
626
|
+
return this.all_tokens.currency.negative;
|
627
|
+
} else {
|
628
|
+
return this.all_tokens.currency.positive;
|
629
|
+
}
|
630
|
+
};
|
631
|
+
|
632
|
+
return CurrencyFormatter;
|
633
|
+
|
634
|
+
})(NumberFormatter);
|
635
|
+
|
636
|
+
TwitterCldr.NumberFormatter.BaseHelper = BaseHelper = (function() {
|
637
|
+
|
638
|
+
function BaseHelper() {}
|
639
|
+
|
640
|
+
BaseHelper.prototype.interpolate = function(string, value, orientation) {
|
641
|
+
var i, length, start;
|
642
|
+
if (orientation == null) {
|
643
|
+
orientation = "right";
|
644
|
+
}
|
645
|
+
value = value.toString();
|
646
|
+
length = value.length;
|
647
|
+
start = orientation === "left" ? 0 : -length;
|
648
|
+
if (string.length < length) {
|
649
|
+
string = (((function() {
|
650
|
+
var _i, _results;
|
651
|
+
_results = [];
|
652
|
+
for (i = _i = 0; 0 <= length ? _i < length : _i > length; i = 0 <= length ? ++_i : --_i) {
|
653
|
+
_results.push("#");
|
654
|
+
}
|
655
|
+
return _results;
|
656
|
+
})()).join("") + string).slice(-length);
|
657
|
+
}
|
658
|
+
if (start < 0) {
|
659
|
+
string = string.slice(0, start + string.length) + value;
|
660
|
+
} else {
|
661
|
+
string = string.slice(0, start) + value + string.slice(length);
|
662
|
+
}
|
663
|
+
return string.replace(/#/g, "");
|
664
|
+
};
|
665
|
+
|
666
|
+
return BaseHelper;
|
667
|
+
|
668
|
+
})();
|
669
|
+
|
670
|
+
TwitterCldr.NumberFormatter.IntegerHelper = IntegerHelper = (function(_super) {
|
671
|
+
|
672
|
+
__extends(IntegerHelper, _super);
|
673
|
+
|
674
|
+
function IntegerHelper(token, symbols) {
|
675
|
+
var format;
|
676
|
+
if (symbols == null) {
|
677
|
+
symbols = {};
|
678
|
+
}
|
679
|
+
format = token.split('.')[0];
|
680
|
+
this.format = this.prepare_format(format, symbols);
|
681
|
+
this.groups = this.parse_groups(format);
|
682
|
+
this.separator = symbols.group || ',';
|
683
|
+
}
|
684
|
+
|
685
|
+
IntegerHelper.prototype.apply = function(number, options) {
|
686
|
+
if (options == null) {
|
687
|
+
options = {};
|
688
|
+
}
|
689
|
+
return this.format_groups(this.interpolate(this.format, parseInt(number)));
|
690
|
+
};
|
691
|
+
|
692
|
+
IntegerHelper.prototype.format_groups = function(string) {
|
693
|
+
var cur_token, token, tokens;
|
694
|
+
if (this.groups.length === 0) {
|
695
|
+
return string;
|
696
|
+
}
|
697
|
+
tokens = [];
|
698
|
+
cur_token = this.chop_group(string, this.groups[0]);
|
699
|
+
tokens.push(cur_token);
|
700
|
+
if (cur_token) {
|
701
|
+
string = string.slice(0, string.length - cur_token.length);
|
702
|
+
}
|
703
|
+
while (string.length > this.groups[this.groups.length - 1]) {
|
704
|
+
cur_token = this.chop_group(string, this.groups[this.groups.length - 1]);
|
705
|
+
tokens.push(cur_token);
|
706
|
+
if (cur_token) {
|
707
|
+
string = string.slice(0, string.length - cur_token.length);
|
708
|
+
}
|
709
|
+
}
|
710
|
+
tokens.push(string);
|
711
|
+
return ((function() {
|
712
|
+
var _i, _len, _results;
|
713
|
+
_results = [];
|
714
|
+
for (_i = 0, _len = tokens.length; _i < _len; _i++) {
|
715
|
+
token = tokens[_i];
|
716
|
+
if (token !== null) {
|
717
|
+
_results.push(token);
|
718
|
+
}
|
719
|
+
}
|
720
|
+
return _results;
|
721
|
+
})()).reverse().join(this.separator);
|
722
|
+
};
|
723
|
+
|
724
|
+
IntegerHelper.prototype.parse_groups = function(format) {
|
725
|
+
var index, rest, width, widths;
|
726
|
+
if (!(index = format.lastIndexOf(','))) {
|
727
|
+
return [];
|
728
|
+
}
|
729
|
+
rest = format.slice(0, index);
|
730
|
+
widths = [format.length - index - 1];
|
731
|
+
if (rest.lastIndexOf(',') > -1) {
|
732
|
+
widths.push(rest.length - rest.lastIndexOf(',') - 1);
|
733
|
+
}
|
734
|
+
widths = (function() {
|
735
|
+
var _i, _len, _results;
|
736
|
+
_results = [];
|
737
|
+
for (_i = 0, _len = widths.length; _i < _len; _i++) {
|
738
|
+
width = widths[_i];
|
739
|
+
if (width !== null) {
|
740
|
+
_results.push(width);
|
741
|
+
}
|
742
|
+
}
|
743
|
+
return _results;
|
744
|
+
})();
|
745
|
+
widths.reverse();
|
746
|
+
return ((function() {
|
747
|
+
var _i, _ref, _results;
|
748
|
+
_results = [];
|
749
|
+
for (index = _i = 0, _ref = widths.length; 0 <= _ref ? _i < _ref : _i > _ref; index = 0 <= _ref ? ++_i : --_i) {
|
750
|
+
if (widths.indexOf(widths[index], index + 1) === -1) {
|
751
|
+
_results.push(widths[index]);
|
752
|
+
}
|
753
|
+
}
|
754
|
+
return _results;
|
755
|
+
})()).reverse();
|
756
|
+
};
|
757
|
+
|
758
|
+
IntegerHelper.prototype.chop_group = function(string, size) {
|
759
|
+
if (string.length > size) {
|
760
|
+
return string.slice(-size);
|
761
|
+
} else {
|
762
|
+
return null;
|
763
|
+
}
|
764
|
+
};
|
765
|
+
|
766
|
+
IntegerHelper.prototype.prepare_format = function(format, symbols) {
|
767
|
+
return format.replace(",", "").replace("+", symbols.plus_sign).replace("-", symbols.minus_sign);
|
768
|
+
};
|
769
|
+
|
770
|
+
return IntegerHelper;
|
771
|
+
|
772
|
+
})(BaseHelper);
|
773
|
+
|
774
|
+
TwitterCldr.NumberFormatter.FractionHelper = FractionHelper = (function(_super) {
|
775
|
+
|
776
|
+
__extends(FractionHelper, _super);
|
777
|
+
|
778
|
+
function FractionHelper(token, symbols) {
|
779
|
+
if (symbols == null) {
|
780
|
+
symbols = {};
|
781
|
+
}
|
782
|
+
this.format = token ? token.split('.').pop() : "";
|
783
|
+
this.decimal = symbols.decimal || ".";
|
784
|
+
this.precision = this.format.length;
|
785
|
+
}
|
786
|
+
|
787
|
+
FractionHelper.prototype.apply = function(fraction, options) {
|
788
|
+
var precision;
|
789
|
+
if (options == null) {
|
790
|
+
options = {};
|
791
|
+
}
|
792
|
+
precision = options.precision != null ? options.precision : this.precision;
|
793
|
+
if (precision > 0) {
|
794
|
+
return this.decimal + this.interpolate(this.format_for(options), fraction, "left");
|
795
|
+
} else {
|
796
|
+
return "";
|
797
|
+
}
|
798
|
+
};
|
799
|
+
|
800
|
+
FractionHelper.prototype.format_for = function(options) {
|
801
|
+
var i, precision;
|
802
|
+
precision = options.precision != null ? options.precision : this.precision;
|
803
|
+
if (precision) {
|
804
|
+
return ((function() {
|
805
|
+
var _i, _results;
|
806
|
+
_results = [];
|
807
|
+
for (i = _i = 0; 0 <= precision ? _i < precision : _i > precision; i = 0 <= precision ? ++_i : --_i) {
|
808
|
+
_results.push("0");
|
809
|
+
}
|
810
|
+
return _results;
|
811
|
+
})()).join("");
|
812
|
+
} else {
|
813
|
+
return this.format;
|
814
|
+
}
|
815
|
+
};
|
816
|
+
|
817
|
+
return FractionHelper;
|
818
|
+
|
819
|
+
})(BaseHelper);
|
820
|
+
|
821
|
+
TwitterCldr.Currencies = Currencies = (function() {
|
822
|
+
|
823
|
+
function Currencies() {}
|
824
|
+
|
825
|
+
Currencies.currencies = {"Afghanistan":{"code":"AFN","currency":"Afghani","symbol":"؋"},"Albania":{"code":"ALL","currency":"Lek","symbol":"Lek"},"Argentina":{"code":"ARS","currency":"Peso","symbol":"$"},"Aruba":{"code":"AWG","currency":"Guilder","symbol":"ƒ"},"Australia":{"code":"AUD","currency":"Dollar","symbol":"$"},"Azerbaijan":{"code":"AZN","currency":"New Manat","symbol":"ман"},"Bahamas":{"code":"BSD","currency":"Dollar","symbol":"$"},"Barbados":{"code":"BBD","currency":"Dollar","symbol":"$"},"Belarus":{"code":"BYR","currency":"Ruble","symbol":"p."},"Belize":{"code":"BZD","currency":"Dollar","symbol":"BZ$"},"Bermuda":{"code":"BMD","currency":"Dollar","symbol":"$"},"Bolivia":{"code":"BOB","currency":"Boliviano","symbol":"$b"},"Bosnia and Herzegovina":{"code":"BAM","currency":"Convertible Marka","symbol":"KM"},"Botswana":{"code":"BWP","currency":"Pula","symbol":"P"},"Brazil":{"code":"BRL","currency":"Real","symbol":"R$"},"Brunei Darussalam":{"code":"BND","currency":"Dollar","symbol":"$"},"Bulgaria":{"code":"BGN","currency":"Lev","symbol":"лв"},"Cambodia":{"code":"KHR","currency":"Riel","symbol":"៛"},"Canada":{"code":"CAD","currency":"Dollar","symbol":"$"},"Cayman Islands":{"code":"KYD","currency":"Dollar","symbol":"$"},"Chile":{"code":"CLP","currency":"Peso","symbol":"$"},"China":{"code":"CNY","currency":"Yuan Renminbi","symbol":"¥"},"Colombia":{"code":"COP","currency":"Peso","symbol":"$"},"Costa Rica":{"code":"CRC","currency":"Colon","symbol":"₡"},"Croatia":{"code":"HRK","currency":"Kuna","symbol":"kn"},"Cuba":{"code":"CUP","currency":"Peso","symbol":"₱"},"Czech Republic":{"code":"CZK","currency":"Koruna","symbol":"Kč"},"Denmark":{"code":"DKK","currency":"Krone","symbol":"kr"},"Dominican Republic":{"code":"DOP","currency":"Peso","symbol":"RD$"},"East Caribbean":{"code":"XCD","currency":"Dollar","symbol":"$"},"Egypt":{"code":"EGP","currency":"Pound","symbol":"£"},"El Salvador":{"code":"SVC","currency":"Colon","symbol":"$"},"Estonia":{"code":"EEK","currency":"Kroon","symbol":"kr"},"Euro Member Countries":{"code":"EUR","currency":"European Union","symbol":"€"},"Falkland Islands (Malvinas)":{"code":"FKP","currency":"Pound","symbol":"£"},"Fiji":{"code":"FJD","currency":"Dollar","symbol":"$"},"Ghana":{"code":"GHC","currency":"Cedis","symbol":"¢"},"Gibraltar":{"code":"GIP","currency":"Pound","symbol":"£"},"Guatemala":{"code":"GTQ","currency":"Quetzal","symbol":"Q"},"Guernsey":{"code":"GGP","currency":"Pound","symbol":"£"},"Guyana":{"code":"GYD","currency":"Dollar","symbol":"$"},"Honduras":{"code":"HNL","currency":"Lempira","symbol":"L"},"Hong Kong":{"code":"HKD","currency":"Dollar","symbol":"$"},"Hungary":{"code":"HUF","currency":"Forint","symbol":"Ft"},"Iceland":{"code":"ISK","currency":"Krona","symbol":"kr"},"India":{"code":"INR","currency":"Rupee","symbol":"₨"},"Indonesia":{"code":"IDR","currency":"Rupiah","symbol":"Rp"},"Iran":{"code":"IRR","currency":"Rial","symbol":"﷼"},"Isle of Man":{"code":"IMP","currency":"Pound","symbol":"£"},"Israel":{"code":"ILS","currency":"Shekel","symbol":"₪"},"Jamaica":{"code":"JMD","currency":"Dollar","symbol":"J$"},"Japan":{"code":"JPY","currency":"Yen","symbol":"¥"},"Jersey":{"code":"JEP","currency":"Pound","symbol":"£"},"Kazakhstan":{"code":"KZT","currency":"Tenge","symbol":"лв"},"Kyrgyzstan":{"code":"KGS","currency":"Som","symbol":"лв"},"Laos":{"code":"LAK","currency":"Kip","symbol":"₭"},"Latvia":{"code":"LVL","currency":"Lat","symbol":"Ls"},"Lebanon":{"code":"LBP","currency":"Pound","symbol":"£"},"Liberia":{"code":"LRD","currency":"Dollar","symbol":"$"},"Lithuania":{"code":"LTL","currency":"Litas","symbol":"Lt"},"Macedonia":{"code":"MKD","currency":"Denar","symbol":"ден"},"Malaysia":{"code":"MYR","currency":"Ringgit","symbol":"RM"},"Mauritius":{"code":"MUR","currency":"Rupee","symbol":"₨"},"Mexico":{"code":"MXN","currency":"Peso","symbol":"$"},"Mongolia":{"code":"MNT","currency":"Tughrik","symbol":"₮"},"Mozambique":{"code":"MZN","currency":"Metical","symbol":"MT"},"Namibia":{"code":"NAD","currency":"Dollar","symbol":"$"},"Nepal":{"code":"NPR","currency":"Rupee","symbol":"₨"},"Netherlands Antilles":{"code":"ANG","currency":"Guilder","symbol":"ƒ"},"New Zealand":{"code":"NZD","currency":"Dollar","symbol":"$"},"Nicaragua":{"code":"NIO","currency":"Cordoba","symbol":"C$"},"Nigeria":{"code":"NGN","currency":"Naira","symbol":"₦"},"North Korea":{"code":"KPW","currency":"Won","symbol":"₩"},"Norway":{"code":"NOK","currency":"Krone","symbol":"kr"},"Oman":{"code":"OMR","currency":"Rial","symbol":"﷼"},"Pakistan":{"code":"PKR","currency":"Rupee","symbol":"₨"},"Panama":{"code":"PAB","currency":"Balboa","symbol":"B/."},"Paraguay":{"code":"PYG","currency":"Guarani","symbol":"Gs"},"Peru":{"code":"PEN","currency":"Nuevo Sol","symbol":"S/."},"Philippines":{"code":"PHP","currency":"Peso","symbol":"₱"},"Poland":{"code":"PLN","currency":"Zloty","symbol":"zł"},"Qatar":{"code":"QAR","currency":"Riyal","symbol":"﷼"},"Romania":{"code":"RON","currency":"New Leu","symbol":"lei"},"Russia":{"code":"RUB","currency":"Ruble","symbol":"руб"},"Saint Helena":{"code":"SHP","currency":"Pound","symbol":"£"},"Saudi Arabia":{"code":"SAR","currency":"Riyal","symbol":"﷼"},"Serbia":{"code":"RSD","currency":"Dinar","symbol":"Дин."},"Seychelles":{"code":"SCR","currency":"Rupee","symbol":"₨"},"Singapore":{"code":"SGD","currency":"Dollar","symbol":"$"},"Solomon Islands":{"code":"SBD","currency":"Dollar","symbol":"$"},"Somalia":{"code":"SOS","currency":"Shilling","symbol":"S"},"South Africa":{"code":"ZAR","currency":"Rand","symbol":"R"},"South Korea":{"code":"KRW","currency":"Won","symbol":"₩"},"Sri Lanka":{"code":"LKR","currency":"Rupee","symbol":"₨"},"Suriname":{"code":"SRD","currency":"Dollar","symbol":"$"},"Sweden":{"code":"SEK","currency":"Krona","symbol":"kr"},"Switzerland":{"code":"CHF","currency":"Franc","symbol":"CHF"},"Syria":{"code":"SYP","currency":"Pound","symbol":"£"},"Taiwan":{"code":"TWD","currency":"New Dollar","symbol":"NT$"},"Thailand":{"code":"THB","currency":"Baht","symbol":"฿"},"Trinidad and Tobago":{"code":"TTD","currency":"Dollar","symbol":"TT$"},"Turkey":{"code":"TRY","currency":"Lira","symbol":"₤"},"Tuvalu":{"code":"TVD","currency":"Dollar","symbol":"$"},"Ukraine":{"code":"UAH","currency":"Hryvna","symbol":"₴"},"United Kingdom":{"code":"GBP","currency":"Pound","symbol":"£"},"United States":{"code":"USD","currency":"Dollar","symbol":"$"},"Uruguay":{"code":"UYU","currency":"Peso","symbol":"$U"},"Uzbekistan":{"code":"UZS","currency":"Som","symbol":"лв"},"Venezuela":{"code":"VEF","currency":"Bolivar Fuerte","symbol":"Bs"},"Viet Nam":{"code":"VND","currency":"Dong","symbol":"₫"},"Yemen":{"code":"YER","currency":"Rial","symbol":"﷼"},"Zimbabwe":{"code":"ZWD","currency":"Dollar","symbol":"Z$"}};
|
826
|
+
|
827
|
+
Currencies.countries = function() {
|
828
|
+
var country_name, data;
|
829
|
+
return this.names || (this.names = (function() {
|
830
|
+
var _ref, _results;
|
831
|
+
_ref = this.currencies;
|
832
|
+
_results = [];
|
833
|
+
for (country_name in _ref) {
|
834
|
+
data = _ref[country_name];
|
835
|
+
_results.push(country_name);
|
836
|
+
}
|
837
|
+
return _results;
|
838
|
+
}).call(this));
|
839
|
+
};
|
840
|
+
|
841
|
+
Currencies.currency_codes = function() {
|
842
|
+
var country_name, data;
|
843
|
+
return this.codes || (this.codes = (function() {
|
844
|
+
var _ref, _results;
|
845
|
+
_ref = this.currencies;
|
846
|
+
_results = [];
|
847
|
+
for (country_name in _ref) {
|
848
|
+
data = _ref[country_name];
|
849
|
+
_results.push(data.code);
|
850
|
+
}
|
851
|
+
return _results;
|
852
|
+
}).call(this));
|
853
|
+
};
|
854
|
+
|
855
|
+
Currencies.for_country = function(country_name) {
|
856
|
+
return this.currencies[country_name];
|
857
|
+
};
|
858
|
+
|
859
|
+
Currencies.for_code = function(currency_code) {
|
860
|
+
var country_name, data, final, _ref;
|
861
|
+
final = null;
|
862
|
+
_ref = this.currencies;
|
863
|
+
for (country_name in _ref) {
|
864
|
+
data = _ref[country_name];
|
865
|
+
if (data.code === currency_code) {
|
866
|
+
final = {
|
867
|
+
country: country_name,
|
868
|
+
code: data.code,
|
869
|
+
symbol: data.symbol,
|
870
|
+
currency: data.currency
|
871
|
+
};
|
872
|
+
break;
|
873
|
+
}
|
874
|
+
}
|
875
|
+
return final;
|
876
|
+
};
|
877
|
+
|
878
|
+
return Currencies;
|
879
|
+
|
880
|
+
})();
|
881
|
+
|
882
|
+
if (typeof exports !== "undefined" && exports !== null) {
|
883
|
+
for (key in TwitterCldr) {
|
884
|
+
obj = TwitterCldr[key];
|
885
|
+
exports[key] = obj;
|
886
|
+
}
|
887
|
+
}
|