1
- /*
2
- * Globalization
3
- * http://github.com/nje/jquery-glob
1
+ /*!
2
+ * jQuery Globalization Plugin
3
+ * http://github.com/jquery/jquery-global
4
+ *
5
+ * Copyright Software Freedom Conservancy, Inc.
6
+ * Dual licensed under the MIT or GPL Version 2 licenses.
7
+ * http://jquery.org/license
4
8
*/
5
9
( function ( ) {
6
10
7
- var Globalization = { } ,
8
- localized = { en : { } } ;
11
+ var Globalization = { } , localized = { en : { } } ;
9
12
localized [ "default" ] = localized . en ;
10
13
11
14
Globalization . extend = function ( deep ) {
@@ -106,10 +109,12 @@ Globalization.preferCulture = function(name) {
106
109
this . culture = this . findClosestCulture ( name ) || this . cultures [ "default" ] ;
107
110
}
108
111
Globalization . localize = function ( key , culture , value ) {
109
- if ( typeof culture === 'string' ) {
110
- culture = culture || "default" ;
111
- culture = this . cultures [ culture ] || { name : culture } ;
112
+ // usign default culture in case culture is not provided
113
+ if ( typeof culture !== 'string' ) {
114
+ culture = this . culture . name || this . culture || "default" ;
112
115
}
116
+ culture = this . cultures [ culture ] || { name : culture } ;
117
+
113
118
var local = localized [ culture . name ] ;
114
119
if ( arguments . length === 3 ) {
115
120
if ( ! local ) {
@@ -146,6 +151,9 @@ Globalization.format = function(value, format, culture) {
146
151
Globalization . parseInt = function ( value , radix , culture ) {
147
152
return Math . floor ( this . parseFloat ( value , radix , culture ) ) ;
148
153
}
154
+ Globalization . parseCurrency = function ( value , culture ) {
155
+ return this . parseFloat ( value . replace ( / [ ^ \d , . - ] / g, "" ) , 10 , culture ) ;
156
+ }
149
157
Globalization . parseFloat = function ( value , radix , culture ) {
150
158
culture = this . findClosestCulture ( culture ) ;
151
159
var ret = NaN ,
@@ -297,7 +305,7 @@ var en = cultures["default"] = cultures.en = Globalization.extend(true, {
297
305
// And the 'zh-SG' culture is Simplified Chinese in Singapore, whose lanugage
298
306
// field is "zh-CHS", not "zh".
299
307
// This field should be used to navigate from a specific culture to it's
300
- // more general, neutral culture. If a culture is already as general as it
308
+ // more general, neutral culture. If a culture is already as general as it
301
309
// can get, the language may refer to itself.
302
310
language : "en" ,
303
311
// numberFormat defines general number formatting rules, like the digits in
@@ -307,7 +315,7 @@ var en = cultures["default"] = cultures.en = Globalization.extend(true, {
307
315
// Note, numberFormat.pattern has no 'positivePattern' unlike percent and currency,
308
316
// but is still defined as an array for consistency with them.
309
317
// negativePattern: one of "(n)|-n|- n|n-|n -"
310
- pattern : [ "-n" ] ,
318
+ pattern : [ "-n" ] ,
311
319
// number of decimal places normally shown
312
320
decimals : 2 ,
313
321
// string that separates number groups, as in 1,000,000
@@ -325,7 +333,7 @@ var en = cultures["default"] = cultures.en = Globalization.extend(true, {
325
333
// [negativePattern, positivePattern]
326
334
// negativePattern: one of "-n %|-n%|-%n|%-n|%n-|n-%|n%-|-% n|n %-|% n-|% -n|n- %"
327
335
// positivePattern: one of "n %|n%|%n|% n"
328
- pattern : [ "-n %" , "n %" ] ,
336
+ pattern : [ "-n %" , "n %" ] ,
329
337
// number of decimal places normally shown
330
338
decimals : 2 ,
331
339
// array of numbers indicating the size of each number group.
@@ -389,7 +397,7 @@ var en = cultures["default"] = cultures.en = Globalization.extend(true, {
389
397
} ,
390
398
// AM and PM designators in one of these forms:
391
399
// The usual view, and the upper and lower case versions
392
- // [standard,lowercase,uppercase]
400
+ // [standard,lowercase,uppercase]
393
401
// The culture does not use AM or PM (likely all standard date formats use 24 hour time)
394
402
// null
395
403
AM : [ "AM" , "am" , "AM" ] ,
@@ -443,7 +451,7 @@ var en = cultures["default"] = cultures.en = Globalization.extend(true, {
443
451
Given the date as a parameter, return an array with parts [year, month, day]
444
452
corresponding to the non-gregorian based year, month, and day for the calendar.
445
453
toGregorian(year, month, day)
446
- Given the non-gregorian year, month, and day, return a new Date() object
454
+ Given the non-gregorian year, month, and day, return a new Date() object
447
455
set to the corresponding date in the gregorian calendar.
448
456
*/
449
457
}
@@ -512,7 +520,7 @@ function expandNumber(number, precision, formatInfo) {
512
520
rounded = number ;
513
521
}
514
522
number = rounded ;
515
-
523
+
516
524
var numberString = number + "" ,
517
525
right = "" ,
518
526
split = numberString . split ( / e / i) ,
@@ -521,7 +529,7 @@ function expandNumber(number, precision, formatInfo) {
521
529
split = numberString . split ( "." ) ;
522
530
numberString = split [ 0 ] ;
523
531
right = split . length > 1 ? split [ 1 ] : "" ;
524
-
532
+
525
533
var l ;
526
534
if ( exponent > 0 ) {
527
535
right = zeroPad ( right , exponent , false ) ;
@@ -728,7 +736,7 @@ function getEraYear(date, cal, era, sortable) {
728
736
// convert normal gregorian year to era-shifted gregorian
729
737
// year by subtracting the era offset
730
738
year -= cal . eras [ era ] . offset ;
731
- }
739
+ }
732
740
return year ;
733
741
}
734
742
@@ -764,7 +772,7 @@ function getMonthIndex(cal, value, abbr) {
764
772
if ( ! upperMonths ) {
765
773
cal . _upperMonths = upperMonths = [
766
774
toUpperArray ( months . names ) ,
767
- toUpperArray ( months . namesAbbr ) ,
775
+ toUpperArray ( months . namesAbbr )
768
776
] ;
769
777
cal . _upperMonthsGen = upperMonthsGen = [
770
778
toUpperArray ( monthsGen . names ) ,
@@ -1153,7 +1161,7 @@ function formatDate(value, format, culture) {
1153
1161
}
1154
1162
return r ;
1155
1163
}
1156
-
1164
+
1157
1165
function hasDay ( ) {
1158
1166
if ( foundDay || checkedDay ) {
1159
1167
return foundDay ;
@@ -1162,7 +1170,7 @@ function formatDate(value, format, culture) {
1162
1170
checkedDay = true ;
1163
1171
return foundDay ;
1164
1172
}
1165
-
1173
+
1166
1174
function getPart ( date , part ) {
1167
1175
if ( converted ) {
1168
1176
return converted [ part ] ;
@@ -1197,7 +1205,7 @@ function formatDate(value, format, culture) {
1197
1205
ret . push ( ar [ 0 ] ) ;
1198
1206
continue ;
1199
1207
}
1200
-
1208
+
1201
1209
var current = ar [ 0 ] ,
1202
1210
clength = current . length ;
1203
1211
@@ -1284,7 +1292,7 @@ function formatDate(value, format, culture) {
1284
1292
// Milliseconds
1285
1293
ret . push ( padZeros ( value . getMilliseconds ( ) , 3 ) . substr ( 0 , clength ) ) ;
1286
1294
break ;
1287
- case "z" :
1295
+ case "z" :
1288
1296
// Time zone offset, no leading zero
1289
1297
case "zz" :
1290
1298
// Time zone offset with leading zero
@@ -1317,17 +1325,7 @@ function formatDate(value, format, culture) {
1317
1325
}
1318
1326
1319
1327
// EXPORTS
1320
-
1321
- window . Globalization = Globalization ;
1322
-
1323
- //jQuery.findClosestCulture = Globalization.findClosestCulture;
1324
- //jQuery.culture = Globalization.culture;
1325
- //jQuery.cultures = Globalization.cultures
1326
- //jQuery.preferCulture = Globalization.preferCulture
1327
- //jQuery.localize = Globalization.localize
1328
- //jQuery.format = Globalization.format
1329
- //jQuery.parseInt = Globalization.parseInt
1330
- //jQuery.parseFloat = Globalization.parseFloat
1331
- //jQuery.parseDate = Globalization.parseDate
1328
+ jQuery . global = Globalization ;
1332
1329
1333
1330
} ) ( ) ;
1331
+
0 commit comments