-/*
- * Globalization
- * http://github.com/nje/jquery-glob
+/*!
+ * jQuery Globalization Plugin
+ * http://github.com/jquery/jquery-global
+ *
+ * Copyright Software Freedom Conservancy, Inc.
+ * Dual licensed under the MIT or GPL Version 2 licenses.
+ * http://jquery.org/license
*/
(function() {
-var Globalization = {},
- localized = { en: {} };
+var Globalization = {}, localized = { en: {} };
localized["default"] = localized.en;
Globalization.extend = function( deep ) {
this.culture = this.findClosestCulture( name ) || this.cultures["default"];
}
Globalization.localize = function(key, culture, value) {
- if (typeof culture === 'string') {
- culture = culture || "default";
- culture = this.cultures[ culture ] || { name: culture };
+ // usign default culture in case culture is not provided
+ if (typeof culture !== 'string') {
+ culture = this.culture.name || this.culture || "default";
}
+ culture = this.cultures[ culture ] || { name: culture };
+
var local = localized[ culture.name ];
if ( arguments.length === 3 ) {
if ( !local) {
Globalization.parseInt = function(value, radix, culture) {
return Math.floor( this.parseFloat( value, radix, culture ) );
}
+Globalization.parseCurrency = function(value, culture) {
+ return this.parseFloat(value.replace(/[^\d,.-]/g, ""), 10, culture);
+}
Globalization.parseFloat = function(value, radix, culture) {
culture = this.findClosestCulture( culture );
var ret = NaN,
// And the 'zh-SG' culture is Simplified Chinese in Singapore, whose lanugage
// field is "zh-CHS", not "zh".
// This field should be used to navigate from a specific culture to it's
- // more general, neutral culture. If a culture is already as general as it
+ // more general, neutral culture. If a culture is already as general as it
// can get, the language may refer to itself.
language: "en",
// numberFormat defines general number formatting rules, like the digits in
// Note, numberFormat.pattern has no 'positivePattern' unlike percent and currency,
// but is still defined as an array for consistency with them.
// negativePattern: one of "(n)|-n|- n|n-|n -"
- pattern: ["-n"],
+ pattern: ["-n"],
// number of decimal places normally shown
decimals: 2,
// string that separates number groups, as in 1,000,000
// [negativePattern, positivePattern]
// negativePattern: one of "-n %|-n%|-%n|%-n|%n-|n-%|n%-|-% n|n %-|% n-|% -n|n- %"
// positivePattern: one of "n %|n%|%n|% n"
- pattern: ["-n %","n %"],
+ pattern: ["-n %","n %"],
// number of decimal places normally shown
decimals: 2,
// array of numbers indicating the size of each number group.
},
// AM and PM designators in one of these forms:
// The usual view, and the upper and lower case versions
- // [standard,lowercase,uppercase]
+ // [standard,lowercase,uppercase]
// The culture does not use AM or PM (likely all standard date formats use 24 hour time)
// null
AM: ["AM", "am", "AM"],
Given the date as a parameter, return an array with parts [year, month, day]
corresponding to the non-gregorian based year, month, and day for the calendar.
toGregorian(year, month, day)
- Given the non-gregorian year, month, and day, return a new Date() object
+ Given the non-gregorian year, month, and day, return a new Date() object
set to the corresponding date in the gregorian calendar.
*/
}
rounded = number;
}
number = rounded;
-
+
var numberString = number+"",
right = "",
split = numberString.split(/e/i),
split = numberString.split( "." );
numberString = split[ 0 ];
right = split.length > 1 ? split[ 1 ] : "";
-
+
var l;
if ( exponent > 0 ) {
right = zeroPad( right, exponent, false );
// convert normal gregorian year to era-shifted gregorian
// year by subtracting the era offset
year -= cal.eras[ era ].offset;
- }
+ }
return year;
}
if ( !upperMonths ) {
cal._upperMonths = upperMonths = [
toUpperArray( months.names ),
- toUpperArray( months.namesAbbr ),
+ toUpperArray( months.namesAbbr )
];
cal._upperMonthsGen = upperMonthsGen = [
toUpperArray( monthsGen.names ),
}
return r;
}
-
+
function hasDay() {
if ( foundDay || checkedDay ) {
return foundDay;
checkedDay = true;
return foundDay;
}
-
+
function getPart( date, part ) {
if ( converted ) {
return converted[ part ];
ret.push( ar[ 0 ] );
continue;
}
-
+
var current = ar[ 0 ],
clength = current.length;
// Milliseconds
ret.push( padZeros( value.getMilliseconds(), 3 ).substr( 0, clength ) );
break;
- case "z":
+ case "z":
// Time zone offset, no leading zero
case "zz":
// Time zone offset with leading zero
}
// EXPORTS
-
-window.Globalization = Globalization;
-
-//jQuery.findClosestCulture = Globalization.findClosestCulture;
-//jQuery.culture = Globalization.culture;
-//jQuery.cultures = Globalization.cultures
-//jQuery.preferCulture = Globalization.preferCulture
-//jQuery.localize = Globalization.localize
-//jQuery.format = Globalization.format
-//jQuery.parseInt = Globalization.parseInt
-//jQuery.parseFloat = Globalization.parseFloat
-//jQuery.parseDate = Globalization.parseDate
+jQuery.global = Globalization;
})();
+