Socket
Socket
Sign inDemoInstall

globalize

Package Overview
Dependencies
Maintainers
4
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

globalize - npm Package Compare versions

Comparing version 0.1.1 to 1.0.0-alpha.1

.bowerrc

9

dist/globalize.min.js

@@ -1,4 +0,5 @@

/*! globalize - v0.1.0pre - 2012-10-18
* http://wiki.jqueryui.com/Globalize
* Copyright 2012 ; Licensed MIT */
(function(e,t){var n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N;n=function(e){return new n.prototype.init(e)},typeof require!="undefined"&&typeof exports!="undefined"&&typeof module!="undefined"?module.exports=n:e.Globalize=n,n.cultures={},n.prototype={constructor:n,init:function(e){return this.cultures=n.cultures,this.cultureSelector=e,this}},n.prototype.init.prototype=n.prototype,n.cultures["default"]={name:"en",englishName:"English",nativeName:"English",isRTL:!1,language:"en",numberFormat:{pattern:["-n"],decimals:2,",":",",".":".",groupSizes:[3],"+":"+","-":"-",NaN:"NaN",negativeInfinity:"-Infinity",positiveInfinity:"Infinity",percent:{pattern:["-n %","n %"],decimals:2,groupSizes:[3],",":",",".":".",symbol:"%"},currency:{pattern:["($n)","$n"],decimals:2,groupSizes:[3],",":",",".":".",symbol:"$"}},calendars:{standard:{name:"Gregorian_USEnglish","/":"/",":":":",firstDay:0,days:{names:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],namesAbbr:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],namesShort:["Su","Mo","Tu","We","Th","Fr","Sa"]},months:{names:["January","February","March","April","May","June","July","August","September","October","November","December",""],namesAbbr:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec",""]},AM:["AM","am","AM"],PM:["PM","pm","PM"],eras:[{name:"A.D.",start:null,offset:0}],twoDigitYearMax:2029,patterns:{d:"M/d/yyyy",D:"dddd, MMMM dd, yyyy",t:"h:mm tt",T:"h:mm:ss tt",f:"dddd, MMMM dd, yyyy h:mm tt",F:"dddd, MMMM dd, yyyy h:mm:ss tt",M:"MMMM dd",Y:"yyyy MMMM",S:"yyyy'-'MM'-'dd'T'HH':'mm':'ss"}}},messages:{}},n.cultures["default"].calendar=n.cultures["default"].calendars.standard,n.cultures.en=n.cultures["default"],n.cultureSelector="en",r=/^0x[a-f0-9]+$/i,i=/^[+\-]?infinity$/i,s=/^[+\-]?\d*\.?\d*(e[+\-]?\d+)?$/,o=/^\s+|\s+$/g,u=function(e,t){if(e.indexOf)return e.indexOf(t);for(var n=0,r=e.length;n<r;n++)if(e[n]===t)return n;return-1},a=function(e,t){return e.substr(e.length-t.length)===t},f=function(){var e,n,r,i,s,o,u=arguments[0]||{},a=1,p=arguments.length,d=!1;typeof u=="boolean"&&(d=u,u=arguments[1]||{},a=2),typeof u!="object"&&!c(u)&&(u={});for(;a<p;a++)if((e=arguments[a])!=null)for(n in e){r=u[n],i=e[n];if(u===i)continue;d&&i&&(h(i)||(s=l(i)))?(s?(s=!1,o=r&&l(r)?r:[]):o=r&&h(r)?r:{},u[n]=f(d,o,i)):i!==t&&(u[n]=i)}return u},l=Array.isArray||function(e){return Object.prototype.toString.call(e)==="[object Array]"},c=function(e){return Object.prototype.toString.call(e)==="[object Function]"},h=function(e){return Object.prototype.toString.call(e)==="[object Object]"},p=function(e,t){return e.indexOf(t)===0},d=function(e){return(e+"").replace(o,"")},v=function(e){return isNaN(e)?NaN:Math[e<0?"ceil":"floor"](e)},m=function(e,t,n){var r;for(r=e.length;r<t;r+=1)e=n?"0"+e:e+"0";return e},g=function(e,t){var n=0,r=!1;for(var i=0,s=e.length;i<s;i++){var o=e.charAt(i);switch(o){case"'":r?t.push("'"):n++,r=!1;break;case"\\":r&&t.push("\\"),r=!r;break;default:t.push(o),r=!1}}return n},y=function(e,t){t=t||"F";var n,r=e.patterns,i=t.length;if(i===1){n=r[t];if(!n)throw"Invalid date format string '"+t+"'.";t=n}else i===2&&t.charAt(0)==="%"&&(t=t.charAt(1));return t},b=function(e,t,n){function T(e,t){var n,r=e+"";return t>1&&r.length<t?(n=c[t-2]+r,n.substr(n.length-t,t)):(n=r,n)}function N(){return h||p?h:(h=d.test(t),p=!0,h)}function C(e,t){if(w)return w[t];switch(t){case 0:return e.getFullYear();case 1:return e.getMonth();case 2:return e.getDate();default:throw"Invalid part value "+t}}var r=n.calendar,i=r.convert,s;if(!t||!t.length||t==="i"){if(n&&n.name.length)if(i)s=b(e,r.patterns.F,n);else{var o=new Date(e.getTime()),u=S(e,r.eras);o.setFullYear(x(e,r,u)),s=o.toLocaleString()}else s=e.toString();return s}var a=r.eras,f=t==="s";t=y(r,t),s=[];var l,c=["0","00","000"],h,p,d=/([^d]|^)(d|dd)([^d]|$)/g,v=0,m=E(),w;!f&&i&&(w=i.fromGregorian(e));for(;;){var k=m.lastIndex,L=m.exec(t),A=t.slice(k,L?L.index:t.length);v+=g(A,s);if(!L)break;if(v%2){s.push(L[0]);continue}var O=L[0],M=O.length;switch(O){case"ddd":case"dddd":var _=M===3?r.days.namesAbbr:r.days.names;s.push(_[e.getDay()]);break;case"d":case"dd":h=!0,s.push(T(C(e,2),M));break;case"MMM":case"MMMM":var D=C(e,1);s.push(r.monthsGenitive&&N()?r.monthsGenitive[M===3?"namesAbbr":"names"][D]:r.months[M===3?"namesAbbr":"names"][D]);break;case"M":case"MM":s.push(T(C(e,1)+1,M));break;case"y":case"yy":case"yyyy":D=w?w[0]:x(e,r,S(e,a),f),M<4&&(D%=100),s.push(T(D,M));break;case"h":case"hh":l=e.getHours()%12,l===0&&(l=12),s.push(T(l,M));break;case"H":case"HH":s.push(T(e.getHours(),M));break;case"m":case"mm":s.push(T(e.getMinutes(),M));break;case"s":case"ss":s.push(T(e.getSeconds(),M));break;case"t":case"tt":D=e.getHours()<12?r.AM?r.AM[0]:" ":r.PM?r.PM[0]:" ",s.push(M===1?D.charAt(0):D);break;case"f":case"ff":case"fff":s.push(T(e.getMilliseconds(),3).substr(0,M));break;case"z":case"zz":l=e.getTimezoneOffset()/60,s.push((l<=0?"+":"-")+T(Math.floor(Math.abs(l)),M));break;case"zzz":l=e.getTimezoneOffset()/60,s.push((l<=0?"+":"-")+T(Math.floor(Math.abs(l)),2)+":"+T(Math.abs(e.getTimezoneOffset()%60),2));break;case"g":case"gg":r.eras&&s.push(r.eras[S(e,a)].name);break;case"/":s.push(r["/"]);break;default:throw"Invalid date format pattern '"+O+"'."}}return s.join("")},function(){var e;e=function(e,t,n){var r=n.groupSizes,i=r[0],s=1,o=Math.pow(10,t),u=Math.round(e*o)/o;isFinite(u)||(u=e),e=u;var a=e+"",f="",l=a.split(/e/i),c=l.length>1?parseInt(l[1],10):0;a=l[0],l=a.split("."),a=l[0],f=l.length>1?l[1]:"";var h;c>0?(f=m(f,c,!1),a+=f.slice(0,c),f=f.substr(c)):c<0&&(c=-c,a=m(a,c+1,!0),f=a.slice(-c,a.length)+f,a=a.slice(0,-c)),t>0?f=n["."]+(f.length>t?f.slice(0,t):m(f,t)):f="";var p=a.length-1,d=n[","],v="";while(p>=0){if(i===0||i>p)return a.slice(0,p+1)+(v.length?d+v+f:f);v=a.slice(p-i+1,p+1)+(v.length?d+v:""),p-=i,s<r.length&&(i=r[s],s++)}return a.slice(0,p+1)+d+v+f},w=function(t,n,r){if(!isFinite(t))return t===Infinity?r.numberFormat.positiveInfinity:t===-Infinity?r.numberFormat.negativeInfinity:r.numberFormat.NaN;if(!n||n==="i")return r.name.length?t.toLocaleString():t.toString();n=n||"D";var i=r.numberFormat,s=Math.abs(t),o=-1,u;n.length>1&&(o=parseInt(n.slice(1),10));var a=n.charAt(0).toUpperCase(),f;switch(a){case"D":u="n",s=v(s),o!==-1&&(s=m(""+s,o,!0)),t<0&&(s="-"+s);break;case"N":f=i;case"C":f=f||i.currency;case"P":f=f||i.percent,u=t<0?f.pattern[0]:f.pattern[1]||"n",o===-1&&(o=f.decimals),s=e(s*(a==="P"?100:1),o,f);break;default:throw"Bad number format specifier: "+a}var l=/n|\$|-|%/g,c="";for(;;){var h=l.lastIndex,p=l.exec(u);c+=u.slice(h,p?p.index:u.length);if(!p)break;switch(p[0]){case"n":c+=s;break;case"$":c+=i.currency.symbol;break;case"-":/[1-9]/.test(s)&&(c+=i["-"]);break;case"%":c+=i.percent.symbol}}return c}}(),E=function(){return/\/|dddd|ddd|dd|d|MMMM|MMM|MM|M|yyyy|yy|y|hh|h|HH|H|mm|m|ss|s|tt|t|fff|ff|f|zzz|zz|z|gg|g/g},S=function(e,t){if(!t)return 0;var n,r=e.getTime();for(var i=0,s=t.length;i<s;i++){n=t[i].start;if(n===null||r>=n)return i}return 0},x=function(e,t,n,r){var i=e.getFullYear();return!r&&t.eras&&(i-=t.eras[n].offset),i},function(){var e,t,n,r,i,s,o;e=function(e,t){if(t<100){var n=new Date,r=S(n),i=x(n,e,r),s=e.twoDigitYearMax;s=typeof s=="string"?(new Date).getFullYear()%100+parseInt(s,10):s,t+=i-i%100,t>s&&(t-=100)}return t},t=function(e,t,n){var r,i=e.days,a=e._upperDays;return a||(e._upperDays=a=[o(i.names),o(i.namesAbbr),o(i.namesShort)]),t=s(t),n?(r=u(a[1],t),r===-1&&(r=u(a[2],t))):r=u(a[0],t),r},n=function(e,t,n){var r=e.months,i=e.monthsGenitive||e.months,a=e._upperMonths,f=e._upperMonthsGen;a||(e._upperMonths=a=[o(r.names),o(r.namesAbbr)],e._upperMonthsGen=f=[o(i.names),o(i.namesAbbr)]),t=s(t);var l=u(n?a[1]:a[0],t);return l<0&&(l=u(n?f[1]:f[0],t)),l},r=function(e,t){var n=e._parseRegExp;if(!n)e._parseRegExp=n={};else{var r=n[t];if(r)return r}var i=y(e,t).replace(/([\^\$\.\*\+\?\|\[\]\(\)\{\}])/g,"\\\\$1"),s=["^"],o=[],u=0,a=0,f=E(),l;while((l=f.exec(i))!==null){var c=i.slice(u,l.index);u=f.lastIndex,a+=g(c,s);if(a%2){s.push(l[0]);continue}var h=l[0],p=h.length,d;switch(h){case"dddd":case"ddd":case"MMMM":case"MMM":case"gg":case"g":d="(\\D+)";break;case"tt":case"t":d="(\\D*)";break;case"yyyy":case"fff":case"ff":case"f":d="(\\d{"+p+"})";break;case"dd":case"d":case"MM":case"M":case"yy":case"y":case"HH":case"H":case"hh":case"h":case"mm":case"m":case"ss":case"s":d="(\\d\\d?)";break;case"zzz":d="([+-]?\\d\\d?:\\d{2})";break;case"zz":case"z":d="([+-]?\\d\\d?)";break;case"/":d="(\\/)";break;default:throw"Invalid date format pattern '"+h+"'."}d&&s.push(d),o.push(l[0])}g(i.slice(u),s),s.push("$");var v=s.join("").replace(/\s+/g,"\\s+"),m={regExp:v,groups:o};return n[t]=m},i=function(e,t,n){return e<t||e>n},s=function(e){return e.split(" ").join(" ").toUpperCase()},o=function(e){var t=[];for(var n=0,r=e.length;n<r;n++)t[n]=s(e[n]);return t},T=function(s,o,u){s=d(s);var a=u.calendar,f=r(a,o),l=(new RegExp(f.regExp)).exec(s);if(l===null)return null;var c=f.groups,h=null,v=null,m=null,g=null,y=null,b=0,w,E=0,S=0,x=0,T=null,N=!1;for(var C=0,k=c.length;C<k;C++){var L=l[C+1];if(L){var A=c[C],O=A.length,M=parseInt(L,10);switch(A){case"dd":case"d":g=M;if(i(g,1,31))return null;break;case"MMM":case"MMMM":m=n(a,L,O===3);if(i(m,0,11))return null;break;case"M":case"MM":m=M-1;if(i(m,0,11))return null;break;case"y":case"yy":case"yyyy":v=O<4?e(a,M):M;if(i(v,0,9999))return null;break;case"h":case"hh":b=M,b===12&&(b=0);if(i(b,0,11))return null;break;case"H":case"HH":b=M;if(i(b,0,23))return null;break;case"m":case"mm":E=M;if(i(E,0,59))return null;break;case"s":case"ss":S=M;if(i(S,0,59))return null;break;case"tt":case"t":N=a.PM&&(L===a.PM[0]||L===a.PM[1]||L===a.PM[2]);if(!N&&(!a.AM||L!==a.AM[0]&&L!==a.AM[1]&&L!==a.AM[2]))return null;break;case"f":case"ff":case"fff":x=M*Math.pow(10,3-O);if(i(x,0,999))return null;break;case"ddd":case"dddd":y=t(a,L,O===3);if(i(y,0,6))return null;break;case"zzz":var _=L.split(/:/);if(_.length!==2)return null;w=parseInt(_[0],10);if(i(w,-12,13))return null;var D=parseInt(_[1],10);if(i(D,0,59))return null;T=w*60+(p(L,"-")?-D:D);break;case"z":case"zz":w=M;if(i(w,-12,13))return null;T=w*60;break;case"g":case"gg":var P=L;if(!P||!a.eras)return null;P=d(P.toLowerCase());for(var H=0,B=a.eras.length;H<B;H++)if(P===a.eras[H].name.toLowerCase()){h=H;break}if(h===null)return null}}}var j=new Date,F,I=a.convert;F=I?I.fromGregorian(j)[0]:j.getFullYear(),v===null?v=F:a.eras&&(v+=a.eras[h||0].offset),m===null&&(m=0),g===null&&(g=1);if(I){j=I.toGregorian(v,m,g);if(j===null)return null}else{j.setFullYear(v,m,g);if(j.getDate()!==g)return null;if(y!==null&&j.getDay()!==y)return null}N&&b<12&&(b+=12),j.setHours(b,E,S,x);if(T!==null){var q=j.getMinutes()-(T+j.getTimezoneOffset());j.setHours(j.getHours()+parseInt(q/60,10),q%60)}return j}}(),N=function(e,t,n){var r=t["-"],i=t["+"],s;switch(n){case"n -":r=" "+r,i=" "+i;case"n-":a(e,r)?s=["-",e.substr(0,e.length-r.length)]:a(e,i)&&(s=["+",e.substr(0,e.length-i.length)]);break;case"- n":r+=" ",i+=" ";case"-n":p(e,r)?s=["-",e.substr(r.length)]:p(e,i)&&(s=["+",e.substr(i.length)]);break;case"(n)":p(e,"(")&&a(e,")")&&(s=["-",e.substr(1,e.length-2)])}return s||["",e]},n.prototype.findClosestCulture=function(e){return n.findClosestCulture.call(this,e)},n.prototype.format=function(e,t,r){return n.format.call(this,e,t,r)},n.prototype.localize=function(e,t){return n.localize.call(this,e,t)},n.prototype.parseInt=function(e,t,r){return n.parseInt.call(this,e,t,r)},n.prototype.parseFloat=function(e,t,r){return n.parseFloat.call(this,e,t,r)},n.prototype.culture=function(e){return n.culture.call(this,e)},n.addCultureInfo=function(e,t,n){var r={},i=!1;typeof e!="string"?(n=e,e=this.culture().name,r=this.cultures[e]):typeof t!="string"?(n=t,i=this.cultures[e]==null,r=this.cultures[e]||this.cultures["default"]):(i=!0,r=this.cultures[t]),this.cultures[e]=f(!0,{},r,n),i&&(this.cultures[e].calendar=this.cultures[e].calendars.standard)},n.findClosestCulture=function(e){var t;if(!e)return this.findClosestCulture(this.cultureSelector)||this.cultures["default"];typeof e=="string"&&(e=e.split(","));if(l(e)){var n,r=this.cultures,i=e,s,o=i.length,u=[];for(s=0;s<o;s++){e=d(i[s]);var a,f=e.split(";");n=d(f[0]),f.length===1?a=1:(e=d(f[1]),e.indexOf("q=")===0?(e=e.substr(2),a=parseFloat(e),a=isNaN(a)?0:a):a=1),u.push({lang:n,pri:a})}u.sort(function(e,t){return e.pri<t.pri?1:e.pri>t.pri?-1:0});for(s=0;s<o;s++){n=u[s].lang,t=r[n];if(t)return t}for(s=0;s<o;s++){n=u[s].lang;do{var c=n.lastIndexOf("-");if(c===-1)break;n=n.substr(0,c),t=r[n];if(t)return t}while(1)}for(s=0;s<o;s++){n=u[s].lang;for(var h in r){var p=r[h];if(p.language==n)return p}}}else if(typeof e=="object")return e;return t||null},n.format=function(e,t,n){var r=this.findClosestCulture(n);return e instanceof Date?e=b(e,t,r):typeof e=="number"&&(e=w(e,t,r)),e},n.localize=function(e,t){return this.findClosestCulture(t).messages[e]||this.cultures["default"].messages[e]},n.parseDate=function(e,t,n){n=this.findClosestCulture(n);var r,i,s;if(t){typeof t=="string"&&(t=[t]);if(t.length)for(var o=0,u=t.length;o<u;o++){var a=t[o];if(a){r=T(e,a,n);if(r)break}}}else{s=n.calendar.patterns;for(i in s){r=T(e,s[i],n);if(r)break}}return r||null},n.parseInt=function(e,t,r){return v(n.parseFloat(e,t,r))},n.parseFloat=function(e,t,n){typeof t!="number"&&(n=t,t=10);var o=this.findClosestCulture(n),u=NaN,a=o.numberFormat;e.indexOf(o.numberFormat.currency.symbol)>-1&&(e=e.replace(o.numberFormat.currency.symbol,""),e=e.replace(o.numberFormat.currency["."],o.numberFormat["."])),e.indexOf(o.numberFormat.percent.symbol)>-1&&(e=e.replace(o.numberFormat.percent.symbol,"")),e=e.replace(/ /g,"");if(i.test(e))u=parseFloat(e);else if(!t&&r.test(e))u=parseInt(e,16);else{var f=N(e,a,a.pattern[0]),l=f[0],c=f[1];l===""&&a.pattern[0]!=="(n)"&&(f=N(e,a,"(n)"),l=f[0],c=f[1]),l===""&&a.pattern[0]!=="-n"&&(f=N(e,a,"-n"),l=f[0],c=f[1]),l=l||"+";var h,p,d=c.indexOf("e");d<0&&(d=c.indexOf("E")),d<0?(p=c,h=null):(p=c.substr(0,d),h=c.substr(d+1));var v,m,g=a["."],y=p.indexOf(g);y<0?(v=p,m=null):(v=p.substr(0,y),m=p.substr(y+g.length));var b=a[","];v=v.split(b).join("");var w=b.replace(/\u00A0/g," ");b!==w&&(v=v.split(w).join(""));var E=l+v;m!==null&&(E+="."+m);if(h!==null){var S=N(h,a,"-n");E+="e"+(S[0]||"+")+S[1]}s.test(E)&&(u=parseFloat(E))}return u},n.culture=function(e){return typeof e!="undefined"&&(this.cultureSelector=e),this.findClosestCulture(e)||this.cultures["default"]}})(this);
/*!
* Globalize v1.0.0-alpha.1 2014-04-11T16:26Z Released under the MIT license
* http://git.io/TrdQbw
*/
!function(a,b){"function"==typeof define&&define.amd?define(["cldr"],b):"object"==typeof exports?module.exports=b(require("cldrjs")):a.Globalize=b(a.Cldr)}(this,function(a){var b,c={};return c.load=function(b){a.load(b)},c.locale=function(c){return arguments.length&&(b=new a(c)),b},c});
{
"name": "globalize",
"version": "0.1.1",
"version": "1.0.0-alpha.1",
"description": "New age globalization and localization. Formats and parses strings, dates and numbers in over 350 cultures.",

@@ -30,2 +30,14 @@ "keywords": [

"author": "The jQuery Project",
"maintainers": [
{
"name": "Jörn Zaefferer",
"email": "joern.zaefferer@gmail.com",
"url": "http://bassistance.de"
},
{
"name": "Rafael Xavier de Souza",
"email": "rxaviers@gmail.com",
"url": "http://rafael.xavier.blog.br"
}
],
"contributors": [

@@ -35,2 +47,3 @@ "Dave Reed <dareed@microsoft.com> (http://weblogs.asp.net/infinitiesloop)",

"Jörn Zaefferer <joern.zaefferer@gmail.com> (http://bassistance.de)",
"Rafael Xavier de Souza <rxaviers@gmail.com> (http://rafael.xavier.blog.br)",
"Legal-Box <legalbox@eric.brechemier.name> (http://www.legal-box.com)",

@@ -41,3 +54,3 @@ "Nikolaus Graf (http://www.nikgraf.com)",

],
"main": "./lib/globalize.js",
"main": "./dist/globalize-allinone-node.js",
"repository": {

@@ -48,6 +61,18 @@ "type": "git",

"bugs": {
"web": "http://github.com/jquery/globalize/issues"
"url": "http://github.com/jquery/globalize/issues"
},
"dependencies": {
"cldrjs": "0.3.3"
},
"devDependencies": {
"grunt": "0.3.17"
"grunt": "0.4.x",
"grunt-contrib-clean": "0.5.0",
"grunt-contrib-connect": "0.3.0",
"grunt-contrib-copy": "0.4.1",
"grunt-contrib-jshint": "0.7.2",
"grunt-contrib-qunit": "0.3.0",
"grunt-contrib-requirejs": "0.4.1",
"grunt-contrib-uglify": "0.2.7",
"grunt-contrib-watch": "0.5.3",
"matchdep": "*"
},

@@ -59,3 +84,6 @@ "licenses": [

}
]
],
"scripts": {
"test": "grunt"
}
}
# Globalize
A JavaScript library for globalization and localization. Enables complex
culture-aware number and date parsing and formatting, including the raw
culture information for hundreds of different languages and countries, as well
as an extensible system for localization.
[![Build Status](https://secure.travis-ci.org/jquery/globalize.png)](http://travis-ci.org/jquery/globalize)
[![devDependency Status](https://david-dm.org/jquery/globalize/dev-status.png)](https://david-dm.org/jquery/globalize#info=devDependencies)
<hr>
<ul>
<li><a href="#why">Why Globalization</a></li>
<li><a href="#what">What is a Culture?</a></li>
<li><a href="#addCultureInfo">Globalize.addCultureInfo</a></li>
<li><a href="#cultures">Globalize.cultures</a></li>
<li><a href="#culture">Globalize.culture</a></li>
<li><a href="#find">Globalize.findClosestCulture</a></li>
<li><a href="#format">Globalize.format</a></li>
<li><a href="#localize">Globalize.localize</a></li>
<li><a href="#parseInt">Globalize.parseInt</a></li>
<li><a href="#parseFloat">Globalize.parseFloat</a></li>
<li><a href="#parseDate">Globalize.parseDate</a></li>
<li><a href="#extend">Utilizing and Extending Cultures</a></li>
<li><a href="#defining">Defining Culture Information</a></li>
<li><a href="#numbers">Number Formatting</a></li>
<li><a href="#currency">Currency Formatting</a></li>
<li><a href="#dates">Date Formatting</a></li>
<li><a href="#generating">Generating Culture Files</a></li>
<li><a href="#building">Building Globalize</a></li>
</ul>
A JavaScript library for internationalization and localization that leverage the
official [Unicode CLDR](http://cldr.unicode.org/) JSON data. The library works both for the browser and as a
Node.js module.
----
## Heads up!
We're working on the migration to using the Unicode CLDR. This is an alpha version of Globalize: 1.0.0-pre.
Patches to the previous stable codebase probably can't be used. If you have a
problem, please create an issue first before trying to patch it.
----
- [Getting started](#getting_started)
- [Why globalization?](#why)
- [About Globalize](#about)
- [Where to use it?](#where)
- [Where does the data come from?](#cldr)
- [Only load and use what you need](#modules)
- [Browser support](#where)
- [Usage](#usage)
- [How to get and load CLDR JSON data](#cldr_usage)
- [API](#api)
- [Core](#core)
- [Globalize.load](#load)
- [Globalize.locale](#locale)
- [Number module](#number)
- [Globalize.formatNumber](#format_number)
- [Globalize.parseNumber](#parse_number)
- [Date module](#date)
- [Globalize.formatDate](#format_date)
- [Globalize.parseDate](#parse_date)
- [Translate module](#translate_module)
- [Globalize.loadTranslation](#load_translations)
- [Globalize.translate](#translate)
- more to come...
- [Development](#development)
- [File structure](#file_structure)
- [Source files](#source_files)
- [Build](#build)
- [Tests](#tests)
<a name="getting_started"></a>
## Getting Started
<a name="why"></a>
<h2 id="why">Why Globalization?</h2>
<p>
### Why globalization?
Each language, and the countries that speak that language, have different

@@ -41,4 +65,3 @@ expectations when it comes to how numbers (including currency and percentages)

those characters differ as well.
</p>
<p>
A user using an application should be able to read and write dates and numbers

@@ -49,59 +72,223 @@ in the format they are accustomed to. This library makes this possible,

and dates into that string format.
</p>
<a name="what"></a>
<h2 id="what">What is a Culture?</h2>
<p>
Globalize defines roughly 350 cultures. Part of the reason for this large
number, besides there being a lot of cultures in the world, is because for
some languages, expectations differ among the countries that speak it.
English, for example, is an official language in dozens of countries. Despite
the language being English, the expected date formatting still greatly differs
between them.
</p>
<p>
So, it does not seem useful to define cultures by their language alone. Nor
is it useful to define a culture by its country alone, as many countries have
several official languages, spoken by sizable populations. Therefore, cultures
are defined as a combination of the language and the country speaking it. Each
culture is given a unique code that is a combination of an ISO 639 two-letter
lowercase culture code for the language, and a two-letter uppercase code for
the country or region. For example, "en-US" is the culture code for English in
the United States.
</p>
<p>
Yet, it is perhaps unreasonable to expect application developers to cater to
every possible language/country combination perfectly. It is important then to
define so-called "neutral" cultures based on each language. These cultures
define the most likely accepted set of rules by anyone speaking that language,
whatever the country. Neutral cultures are defined only by their language code.
For example, "es" is the neutral culture for Spanish.
</p>
<a name="addCultureInfo"></a>
<h2 id="addCultureInfo">Globalize.addCultureInfo( cultureName, extendCultureName, info )</h2>
<p>
This method allows you to create a new culture based on an existing culture or
add to existing culture info. If the optional argument <pre>extendCultureName</pre>
is not supplied, it will extend the existing culture if it exists or create a new
culture based on the default culture if it doesn't exist. If cultureName is not
supplied, it will add the supplied info to the current culture. See .culture().
</p>
<a name="about"></a>
### About Globalize
<a name="where"></a>
#### Where to use it?
<a name="cultures"></a>
<h2 id="cultures">Globalize.cultures</h2>
<p>
A mapping of culture codes to culture objects. For example,
Globalize.cultures.fr is an object representing the complete culture
definition for the neutral French culture. Note that the main globalize.js file
alone only includes a neutral English culture. To get additional cultures, you
must include one or more of the culture scripts that come with it. You
can see in the section <a href="#defining">Defining Culture Information</a>
below which fields are defined in each culture.
</p>
It's designed to work both in the [browser](#browser_support), or in
[Node.js](#usage). It supports both [AMD](#usage) and [CommonJS](#usage).
<a name="culture"></a>
<h2 id="culture">Globalize.culture( selector )</h2>
<p>
<a name="cldr"></a>
#### Where does the data come from?
Globalize uses the [Unicode CLDR](http://cldr.unicode.org/), the largest and
most extensive standard repository of locale data.
We do NOT embed any i18n data within our library. However, we make it really
easy to use. Read the section [How to get and load CLDR JSON data](#cldr_usage) for
more information on its usage.
<a name="modules"></a>
#### Load and use only what you need
Globalize is split in modules: core, number (coming soon), date, and translate.
We're evaluating other modules, eg. plural, ordinals, etc.
The core implements [`Globalize.load( cldrData )`](#load), and
[`Globalize.locale( locale )`](#locale).
The date module extends core Globalize, and adds [`Globalize.formatDate( value,
pattern, locale )`](#format_date), and [`Globalize.parseDate( value, patterns, locale
)`](#parse_date).
The translate module extends core Globalize, and adds
[`Globalize.loadTranslations( locale, json )`](#load_translations), and
[`Globalize.translate( path , locale )`](#translate).
More to come...
<a name="browser_support"></a>
#### Browser Support
We officially support:
- Firefox (latest - 1)+
- Chrome (latest - 1)+
- Safari 5.1+
- IE 8+
- Opera (latest - 1)+
Dry tests show Globalize also works on the following browsers:
- Firefox 4+
- Safari 5+
- Chrome 14+
- IE 6+
- Opera 11.1+
If you find any bugs, please just [let us
know](https://github.com/jquery/globalize/issues). We'll be glad to fix them for
the officially supported browsers, or at least to update the documentation for
the unsupported ones.
<a name="usage"></a>
## Usage
All distributables are UMD wrapped. So, it supports AMD, CommonJS, or global
variables (in case neither AMD nor CommonJS have been detected).
Example of usage with script tags:
```html
<script src="./external/cldrjs/dist/cldr.js"></script>
<script src="./dist/globalize.js"></script>
<script src="./dist/globalize/date.js"></script>
```
Example of usage on AMD:
```bash
bower install cldrjs globalize
```
```javascript
require.config({
paths: {
cldr: "bower_components/cldrjs/dist/cldr.runtime",
globalize: "bower_components/globalize/dist/globalize"
}
});
require( [ "globalize", "globalize/date" ], function( Globalize ) {
...
});
```
Example of usage with Node.js:
```bash
npm install cldrjs globalize
```
```javascript
var Globalize = require( "globalize" );
...
```
<a name="cldr_usage"></a>
### How to get and load CLDR JSON data
The Unicode CLDR is available for download as JSON
([`json.zip`](http://www.unicode.org/Public/cldr/latest/json.zip)). This file
contains the complete data of what the Unicode CLDR Project considers the top
20 languages (at the time of this writing).
You can generate the JSON representation of the languages not available in the
ZIP file by using the official conversion tool
([`tools.zip`](http://www.unicode.org/Public/cldr/latest/)). This ZIP contains a
README with instructions on how to build the data.
You can choose to generate unresolved data to save space or bandwidth (`-r false`
option of the conversion tool), and instead have it resolve at runtime.
For the examples below, first fetch CLDR JSON data:
```bash
wget http://www.unicode.org/Public/cldr/latest/json.zip
unzip json.zip -d cldr
```
Example of embedding CLDR JSON data:
```html
<script>
Globalize.load({
main: {
en: {
...
}
},
supplemental: {
likelySubtags: {
...
},
timeDate: {
...
},
weekData: {
...
}
}
});
</script>
```
Example of loading it dynamically:
```html
<script src="jquery.js"></script>
<script>
$.get( "cldr/en/ca-gregorian.json", Globalize.load );
$.get( "cldr/supplemental/likelySubtags.json", Globalize.load );
$.get( "cldr/supplemental/timeData.json", Globalize.load );
$.get( "cldr/supplemental/weekData.json", Globalize.load );
</script>
```
Example using AMD (also see our [functional tests](test/functional.js)):
```javascript
define([
"globalize",
"json!fixtures/cldr/main/en/ca-gregorian.json",
"json!fixtures/cldr/supplemental/likelySubtags.json",
"json!fixtures/cldr/supplemental/timeData.json",
"json!fixtures/cldr/supplemental/weekData.json",
"globalize/date"
], function( Globalize, enCaGregorian, likelySubtags, timeData, weekData ) {
Globalize.load( enCaGregorian );
Globalize.load( likelySubtags );
Globalize.load( timeData );
Globalize.load( weekData );
});
```
Example using Node.js:
```javascript
var Globalize = require( "globalize" );
Globalize.load( require( "./cldr/supplemental/likelySubtags.json" ) );
Globalize.load( require( "./cldr/supplemental/timeData.json" ) );
Globalize.load( require( "./cldr/supplemental/weekData.json" ) );
Globalize.load( require( "./cldr/en/ca-gregorian.json" ) );
```
<a name="api"></a>
## API
<a name="core"></a>
### Core module
<a name="load"></a>
#### `Globalize.load( cldrJSONData )`
This method allows you to load CLDR JSON locale data. `Globalize.load()` is a
proxy to `Cldr.load()`. For more information, see
https://github.com/rxaviers/cldrjs#readme.
Parameters:
- **cldrJSONData** A JSON object with CLDR data. See ["How to get and load CLDR
JSON data" above](#cldr_usage) for more information and examples;
<a name="locale"></a>
#### `Globalize.locale( [locale] )`
Set default locale, or get it if locale argument is omitted.
Parameters:
- **locale** The locale string, eg. "en", "pt_BR", or "zh_Hant_TW".
An application that supports globalization and/or localization will need to

@@ -111,758 +298,294 @@ have a way to determine the user's preference. Attempting to automatically

offer the user a choice, by whatever means.
</p>
<p>
Whatever your mechanism, it is likely that you will have to correlate the
user's preferences with the list of cultures supported in the app. This
method allows you to select the best match given the culture scripts that you
have included and to set the Globalize culture to the culture which the user
user's preferences with the list of locale data supported in the app. This
method allows you to select the best match given the locale data that you
have included and to set the Globalize locale to the one which the user
prefers.
</p>
<p>
If you pass an array of names instead of a single name string, the first
culture for which there is a match (that culture's script has been referenced)
will be used. If none match, the search restarts using the corresponding
neutral cultures. For example, if the application has included only the neutral
"fr" culture, any of these would select it:
<pre>
Globalize.culture( "fr" );
console.log( Globalize.culture().name ) // "fr"
Globalize.culture( "fr-FR" );
console.log( Globalize.culture().name ) // "fr-FR"
```javascript
Globalize.locale( "pt" );
console.log( Globalize.locale().attributes );
// {
// "languageId": "pt",
// "maxLanguageId": "pt_Latn_BR",
// "language": "pt",
// "script": "Latn",
// "territory": "BR",
// "region": "BR"
// }
```
Globalize.culture([ "es-MX", "fr-FR" ]);
console.log( Globalize.culture().name ) // "es-MX"
</pre>
LanguageMatching TBD (CLDR's spec http://www.unicode.org/reports/tr35/#LanguageMatching).
In any case, if no match is found, the neutral English culture "en" is selected
by default.
If you don't pass a selector, .culture() will return the current Globalize
culture.
</p>
<p>
Each culture string may also follow the pattern defined in
<a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4"
>RFC2616 sec 14.4</a>. That is, a culture name may include a "quality" value
that indicates an estimate of the user's preference for the language.
<a name="number"></a>
### Number module
<pre>
Globalize.culture( "fr;q=0.4, es;q=0.5, he" );
</pre>
In this example, the neutral Hebrew culture "he" is given top priority (an
unspecified quality is equal to 1). If that language is not an exact match for
any of the cultures available in Globalize.cultures, then "es" is the next
highest priority with 0.5, etc. If none of these match, just like with the array
syntax, the search starts over and the same rules are applied to the
corresponding neutral language culture for each. If still none match, the
neutral English culture "en" is used.
</p>
<a name="format_number"></a>
#### `Globalize.formatNumber( value [, attributes] [, locale] )`
<a name="find"></a>
<h2 id="find">Globalize.findClosestCulture( selector )</h2>
<p>
Just like .culture( selector ), but it just returns the matching culture, if
any, without setting it to the current Globalize culture, returned by
.culture().
</p>
Format a number according to the given attributes and the given locale (or the
default locale if not specified).
<a name="format"></a>
<h2 id="format">Globalize.format( value, format, culture )</h2>
<p>
Formats a date or number according to the given format string and the given
culture (or the current culture if not specified). See the sections
<a href="#numbers">Number Formatting</a> and
<a href="#dates">Date Formatting</a> below for details on the available
formats.
<pre>
// assuming a culture with number grouping of 3 digits,
// using "," separator and "." decimal symbol.
Globalize.format( 1234.567, "n" ); // "1,234.57"
Globalize.format( 1234.567, "n1" ); // "1,234.6"
Globalize.format( 1234.567, "n0" ); // "1,235"
Parameters:
// assuming a culture with "/" as the date separator symbol
Globalize.format( new Date(1955,10,5), "yyyy/MM/dd" ); // "1955/11/05"
Globalize.format( new Date(1955,10,5), "dddd MMMM d, yyyy" ); // "Saturday November 5, 1955"
</pre>
</p>
- **value** Number to be formatted, eg. `3.14`;
- **attributes** Optional
- style: Optional String `decimal` (default), or `percent`;
- minimumIntegerDigits: Optional non-negative integer Number value indicating
the minimum integer digits to be used. Numbers will be padded with leading
zeroes if necessary;
- minimumFractionDigits and maximumFractionDigits: Optional non-negative
integer Number values indicating the minimum and maximum fraction digits to
be used. Numbers will be rounded or padded with trailing zeroes if
necessary;
- minimumSignificantDigits and maximumSignificantDigits: Optional positive
integer Number values indicating the minimum and maximum fraction digits to
be shown. Either none or both of these properties are present; if they are,
they override minimum and maximum integer and fraction digits. The formatter
uses however many integer and fraction digits are required to display the
specified number of significant digits;
- round: Optional String with rounding method `ceil`, `floor`, `round`
(default), or `truncate`;
- useGrouping: Optional boolean (default is true) value indicating whether a
grouping separator should be used;
- **locale** Optional locale string that overrides default;
<a name="localize"></a>
<h2 id="localize">Globalize.localize( key, culture )</h2>
<p>
Gets or sets a localized value. This method allows you to extend the
information available to a particular culture, and to easily retrieve it
without worrying about finding the most appropriate culture. For example, to
define the word "translate" in French:
<pre>
Globalize.addCultureInfo( "fr", {
messages: {
"translate": "traduire"
}
```javascript
Globalize.locale( "en" );
Globalize.formatNumber( 3.141592 ); // "3.142"
Globalize.formatNumber( 3.141592, {}, "es" ); // "3,142"
Globalize.formatNumber( 3.141592, {}, "ar" ); // "3٫142"
```
Controlling digits by specifying integer and fraction digits counts:
```
Globalize.formatNumber( 3.141592, { maximumFractionDigits: 2 } );
// "3.14"
Globalize.formatNumber( 1.5, { minimumFractionDigits: 2 } );
// "1.50"
```
Controlling digits by specifying significant digits counts:
```
Globalize.formatNumber( 3.141592, {
minimumSignificantDigits: 1,
maximumSignificantDigits: 3
});
console.log( Globalize.localize( "translate", "fr" ) ); // "traduire"
</pre>
Note that localize() will find the closest match available per the same
semantics as the Globalize.findClosestCulture() method. If there is no
match, the translation given is for the neutral English culture "en" by
default.
</p>
// "3.14"
Globalize.formatNumber( 12345, {
minimumSignificantDigits: 1,
maximumSignificantDigits: 3
});
// "12,300"
<a name="parseInt"></a>
<h2 id="parseInt">Globalize.parseInt( value, radix, culture )</h2>
<p>
Parses a string representing a whole number in the given radix (10 by default),
taking into account any formatting rules followed by the given culture (or the
current culture, if not specified).
equal( Globalize.formatNumber( 0.00012345, {
minimumSignificantDigits: 1,
maximumSignificantDigits: 3
});
// "0.000123"
```
If a percentage is passed into parseInt, the percent sign will be removed and the number parsed as is.
Example: 12.34% would be returned as 12.
<pre>
// assuming a culture where "," is the group separator
// and "." is the decimal separator
Globalize.parseInt( "1,234.56" ); // 1234
// assuming a culture where "." is the group separator
// and "," is the decimal separator
Globalize.parseInt( "1.234,56" ); // 1234
</pre>
</p>
Using different rounding functions example:
<a name="parseFloat"></a>
<h2 id="parseFloat">Globalize.parseFloat( value, radix, culture )</h2>
<p>
Parses a string representing a floating point number in the given radix (10 by
default), taking into account any formatting rules followed by the given
culture (or the current culture, if not specified).
```
Globalize.formatNumber( 3.141592, { maximumFractionDigits: 2, round: "ceil" } );
// "3.15"
```
If a percentage is passed into parseFloat, the percent sign will be removed and the number parsed as is.
Example: 12.34% would be returned as 12.34
<pre>
// assuming a culture where "," is the group separator
// and "." is the decimal separator
Globalize.parseFloat( "1,234.56" ); // 1234.56
// assuming a culture where "." is the group separator
// and "," is the decimal separator
Globalize.parseFloat( "1.234,56" ); // 1234.56
</pre>
</p>
<a name="parse_number"></a>
#### `Globalize.parseNumber( value, [formats], [locale] )`
<a name="parseDate"></a>
<h2 id="parseDate">Globalize.parseDate( value, formats, culture )</h2>
<p>
Parses a string representing a date into a JavaScript Date object, taking into
account the given possible formats (or the given culture's set of default
formats if not given). As before, the current culture is used if one is not
TBD
<a name="date"></a>
### Date module
<a name="format_date"></a>
#### `Globalize.formatDate( value, format [, locale] )`
Format a date according to the given format and locale (or the current locale if not specified).
Parameters:
- **value** Date instance to be formatted, eg. `new Date()`;
- **format**
- String, skeleton. Eg "GyMMMd";
- Object, accepts either one:
- Skeleton, eg. `{ skeleton: "GyMMMd" }`. List of all skeletons [TODO];
- Date, eg. `{ date: "full" }`. Possible values are full, long, medium, short;
- Time, eg. `{ time: "full" }`. Possible values are full, long, medium, short;
- Datetime, eg. `{ datetime: "full" }`. Possible values are full, long, medium, short;
- Raw pattern, eg. `{ pattern: "dd/mm" }`. [List of all date
patterns](http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table);
- **locale** Optional locale string that overrides default;
```javascript
Globalize.formatDate( new Date( 2010, 10, 30, 17, 55 ), { datetime: "short" } );
// "11/30/10, 5:55 PM"
Globalize.formatDate( new Date( 2010, 10, 30, 17, 55 ), { datetime: "short" }, "de" );
// "30.11.10 17:55"
```
Comparison between different locales.
| locale | `Globalize.formatDate( new Date( 2010, 10, 1, 17, 55 ), { datetime: "short" } )` |
| --- | --- |
| **en** | `"11/1/10, 5:55 PM"` |
| **en_GB** | `"01/11/2010 17:55"` |
| **de** | `"01.11.10 17:55"` |
| **zh** | `"10/11/1 下午5:55"` |
| **ar** | `"1‏/11‏/2010 5:55 م"` |
| **pt** | `"01/11/10 17:55"` |
| **es** | `"1/11/10 17:55"` |
<a name="parse_date"></a>
#### `Globalize.parseDate( value [, formats] [, locale] )`
Parse a string representing a date into a JavaScript Date object, taking into
account the given possible formats (or the given locale's set of preset
formats if not provided). As before, the current locale is used if one is not
specified.
<pre>
Globalize.culture( "en" );
Globalize.parseDate( "1/2/2003" ); // Thu Jan 02 2003
Globalize.culture( "fr" );
Globalize.parseDate( "1/2/2003" ); // Sat Feb 01 2003
</pre>
</p>
<a name="extend"></a>
<h2 id="extend">Utilizing and Extending Cultures</h2>
<p>
The culture information included with each culture is mostly necessary for the
parsing and formatting methods, but not all of it. For example, the Native and
English names for each culture is given, as well as a boolean indicating
whether the language is right-to-left. This may be useful information for your
own purposes. You may also add to the culture information directly if so
desired.
</p>
<p>
As an example, in the U.S., the word "billion" means the number 1,000,000,000
(9 zeros). But in other countries, that number is "1000 million" or a
"milliard", and a billion is 1,000,000,000,000 (12 zeros). If you needed to
provide functionality to your app or custom plugin that needed to know how many
zeros are in a "billion", you could extend the culture information as follows:
<pre>
// define additional culture information for a possibly existing culture
Globalize.addCultureInfo( "fr", {
numberFormat: {
billionZeroes: 12
}
Parameters:
- **value** String with date to be parsed, eg. `"11/1/10, 5:55 PM"`;
- **formats** Optional array of formats;
- **locale** Optional locale string that overrides default
```javascript
Globalize.locale( "en" );
Globalize.parseDate( "1/2/13" );
// Wed Jan 02 2013 00:00:00
Globalize.locale( "es" );
Globalize.parseDate( "1/2/13" );
// Fri Feb 01 2013 00:00:00
```
<a name="translate_module"></a>
### Translate module
<a name="load_translations"></a>
#### `Globalize.loadTranslation( locale, translationData )`
Load translation data per locale.
Parameters:
- **locale** Locale string;
- **translationData** A JSON object with translation mappings;
```javascript
Globalize.loadTranslation( "pt_BR", {
greetings: {
hello: "Olá",
bye: "Tchau"
}
});
</pre>
Using this mechanism, the "fr" culture will be created if it does not exist.
And if it does, the given values will be added to it.
</p>
```
<a name="defining"></a>
<h2 id="defining">Defining Culture Information</h2>
<p>
Each culture is defined in its own script with the naming scheme
globalize.culture.&lt;name&gt;.js. You may include any number of these scripts,
making them available in the Globalize.cultures mapping. Including one of
these scripts does NOT automatically make it the current culture selected in the
Globalize.culture property.
</p>
<p>
The neutral English culture is defined directly in globalize.js, and set
both to the properties "en" and "default" of the Globalize.cultures mapping.
Extensive comments describe the purpose of each of the fields defined.
</p>
<p>
Looking at the source code of the scripts for each culture, you will notice
that each script uses Globalize.addCultureInfo() to have the "default" neutral
English culture "en", as a common basis, and defines only the properties that
differ from neutral English.
</p>
<p>
The neutral English culture is listed here along with the comments:
<pre>
Globalize.cultures[ "default" ] = {
// A unique name for the culture in the form
// &lt;language code&gt;-&lt;country/region code&gt;
name: "English",
// the name of the culture in the English language
englishName: "English",
// the name of the culture in its own language
nativeName: "English",
// whether the culture uses right-to-left text
isRTL: false,
// "language" is used for so-called "specific" cultures.
// For example, the culture "es-CL" means Spanish in Chili.
// It represents the Spanish-speaking culture as it is in Chili,
// which might have different formatting rules or even translations
// than Spanish in Spain. A "neutral" culture is one that is not
// specific to a region. For example, the culture "es" is the generic
// Spanish culture, which may be a more generalized version of the language
// that may or may not be what a specific culture expects.
// For a specific culture like "es-CL", the "language" field refers to the
// neutral, generic culture information for the language it is using.
// This is not always a simple matter of the string before the dash.
// For example, the "zh-Hans" culture is neutral (Simplified Chinese).
// And the "zh-SG" culture is Simplified Chinese in Singapore, whose
// language field is "zh-CHS", not "zh".
// This field should be used to navigate from a specific culture to its
// 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 each grouping, the group separator, and how negative numbers are
// displayed.
numberFormat: {
// [negativePattern]
// 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" ],
// number of decimal places normally shown
decimals: 2,
// string that separates number groups, as in 1,000,000
",": ",",
// string that separates a number from the fractional portion,
// as in 1.99
".": ".",
// array of numbers indicating the size of each number group.
groupSizes: [ 3 ],
// symbol used for positive numbers
"+": "+",
// symbol used for negative numbers
"-": "-",
percent: {
// [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 %" ],
// number of decimal places normally shown
decimals: 2,
// array of numbers indicating the size of each number group.
groupSizes: [ 3 ],
// string that separates number groups, as in 1,000,000
",": ",",
// string that separates a number from the fractional portion, as in 1.99
".": ".",
// symbol used to represent a percentage
symbol: "%"
},
currency: {
// [negativePattern, positivePattern]
// negativePattern: one of "($n)|-$n|$-n|$n-|(n$)|-n$|n-$|n$-|-n $|-$ n|n $-|$ n-|$ -n|n- $|($ n)|(n $)"
// positivePattern: one of "$n|n$|$ n|n $"
pattern: [ "($n)", "$n" ],
// number of decimal places normally shown
decimals: 2,
// array of numbers indicating the size of each number group.
groupSizes: [ 3 ],
// string that separates number groups, as in 1,000,000
",": ",",
// string that separates a number from the fractional portion, as in 1.99
".": ".",
// symbol used to represent currency
symbol: "$"
}
},
// "calendars" property defines all the possible calendars used by this
// culture. There should be at least one defined with name "standard" which
// is the default calendar used by the culture.
// A calendar contains information about how dates are formatted,
// information about the calendar's eras, a standard set of the date
// formats, translations for day and month names, and if the calendar is
// not based on the Gregorian calendar, conversion functions to and from
// the Gregorian calendar.
calendars: {
standard: {
// name that identifies the type of calendar this is
name: "Gregorian_USEnglish",
// separator of parts of a date (e.g. "/" in 11/05/1955)
"/": "/",
// separator of parts of a time (e.g. ":" in 05:44 PM)
":": ":",
// the first day of the week (0 = Sunday, 1 = Monday, etc)
firstDay: 0,
days: {
// full day names
names: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ],
// abbreviated day names
namesAbbr: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
// shortest day names
namesShort: [ "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" ]
},
months: [
// full month names (13 months for lunar calendars -- 13th month should be "" if not lunar)
names: [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", "" ],
// abbreviated month names
namesAbbr: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "" ]
],
// AM and PM designators in one of these forms:
// The usual view, and the upper and lower case versions
// [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" ],
PM: [ "PM", "pm", "PM" ],
eras: [
// eras in reverse chronological order.
// name: the name of the era in this culture (e.g. A.D., C.E.)
// start: when the era starts in ticks, null if it is the
// earliest supported era.
// offset: offset in years from gregorian calendar
{"name":"A.D.","start":null,"offset":0}
],
// when a two digit year is given, it will never be parsed as a
// four digit year greater than this year (in the appropriate era
// for the culture)
// Set it as a full year (e.g. 2029) or use an offset format
// starting from the current year: "+19" would correspond to 2029
// if the current year is 2010.
twoDigitYearMax: 2029,
// set of predefined date and time patterns used by the culture.
// These represent the format someone in this culture would expect
// to see given the portions of the date that are shown.
patterns: {
// short date pattern
d: "M/d/yyyy",
// long date pattern
D: "dddd, MMMM dd, yyyy",
// short time pattern
t: "h:mm tt",
// long time pattern
T: "h:mm:ss tt",
// long date, short time pattern
f: "dddd, MMMM dd, yyyy h:mm tt",
// long date, long time pattern
F: "dddd, MMMM dd, yyyy h:mm:ss tt",
// month/day pattern
M: "MMMM dd",
// month/year pattern
Y: "yyyy MMMM",
// S is a sortable format that does not vary by culture
S: "yyyy\u0027-\u0027MM\u0027-\u0027dd\u0027T\u0027HH\u0027:\u0027mm\u0027:\u0027ss"
}
// optional fields for each calendar:
/*
monthsGenitive:
Same as months but used when the day preceeds the month.
Omit if the culture has no genitive distinction in month names.
For an explanation of genitive months, see
http://blogs.msdn.com/michkap/archive/2004/12/25/332259.aspx
convert:
Allows for the support of non-gregorian based calendars. This
"convert" object defines two functions to convert a date to and
from a gregorian calendar date:
fromGregorian( date )
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 set to the corresponding date in the
gregorian calendar.
*/
}
},
// Map of messages used by .localize()
messages: {}
}
</pre>
</p>
<p>
Each culture can have several possible calendars. The calendar named "standard"
is the default calendar used by that culture. You may change the calendar in
use by setting the "calendar" field. Take a look at the calendars defined by
each culture by looking at the script or enumerating its calendars collection.
<pre>
// switch to a non-standard calendar
Globalize.culture().calendar = Globalize.culture().calendars.SomeOtherCalendar;
// back to the standard calendar
Globalize.culture().calendar = Globalize.culture().calendars.standard;
</pre>
<a name="translate"></a>
#### `Globalize.translate( path [, locale] )`
</p>
Translate item given its path.
<a name="numbers"></a>
<h2 id="numbers">Number Formatting</h2>
<p>
When formatting a number with format(), the main purpose is to convert the
number into a human readable string using the culture's standard grouping and
decimal rules. The rules between cultures can vary a lot. For example, in some
cultures, the grouping of numbers is done unevenly. In the "te-IN" culture
(Telugu in India), groups have 3 digits and then 2 digits. The number 1000000
(one million) is written as "10,00,000". Some cultures do not group numbers at
all.
</p>
<p>
There are four main types of number formatting:
<ul>
<li><strong>n</strong> for number</li>
<li><strong>d</strong> for decimal digits</li>
<li><strong>p</strong> for percentage</li>
<li><strong>c</strong> for currency</li>
</ul>
Even within the same culture, the formatting rules can vary between these four
types of numbers. For example, the expected number of decimal places may differ
from the number format to the currency format. Each format token may also be
followed by a number. The number determines how many decimal places to display
for all the format types except decimal, for which it means the minimum number
of digits to display, zero padding it if necessary. Also note that the way
negative numbers are represented in each culture can vary, such as what the
negative sign is, and whether the negative sign appears before or after the
number. This is especially apparent with currency formatting, where many
cultures use parentheses instead of a negative sign.
<pre>
// just for example - will vary by culture
Globalize.format( 123.45, "n" ); // 123.45
Globalize.format( 123.45, "n0" ); // 123
Globalize.format( 123.45, "n1" ); // 123.5
Parameters:
- **path** Translation item path;
- **locale** Optional locale string that overrides default
Globalize.format( 123.45, "d" ); // 123
Globalize.format( 12, "d3" ); // 012
```javascript
Globalize.locale( "pt_BR" );
Globalize.translate( "greetings/bye" );
// ➡ "Tchau"
```
Globalize.format( 123.45, "c" ); // $123.45
Globalize.format( 123.45, "c0" ); // $123
Globalize.format( 123.45, "c1" ); // $123.5
Globalize.format( -123.45, "c" ); // ($123.45)
Globalize.format( 0.12345, "p" ); // 12.35 %
Globalize.format( 0.12345, "p0" ); // 12 %
Globalize.format( 0.12345, "p4" ); // 12.3450 %
</pre>
Parsing with parseInt and parseFloat also accepts any of these formats.
</p>
<a name="development"></a>
## Development
<a name="currency"></a>
<h2 id="currency">Currency Formatting</h2>
<p>
Globalize has a default currency symbol for each locale. This is used when
formatting a currency value such as
<pre>
Globalize.format( 1234.56, "c" ); // $1,234.56
</pre>
You can change the currency symbol for a locale by modifying the culture's
<code>numberFormat.currency.symbol</code> property:
<pre>
Globalize.culture( "en-US" ).numberFormat.currency.symbol = '\u20ac'; // euro sign U+20AC
</pre>
If you need to switch between currency symbols, you could write a function
to do that, such as
<pre>
function setCurrency( currSym ) {
Globalize.culture().numberFormat.currency.symbol = currSym;
}
</pre>
<a name="file_structure"></a>
### File structure
```
├── bower.json (metadata file)
├── CONTRIBUTING.md (doc file)
├── dist/ (output of built bundles)
├── external/ (external dependencies, eg. cldr.js, QUnit, RequireJS)
├── Gruntfile.js (Grunt tasks)
├── LICENSE (license file)
├── package.json (metadata file)
├── README.md (doc file)
├── src/ (source code)
│ ├── build/ (build helpers, eg. intro, and outro)
│ ├── common/ (common function helpers across modules)
│ ├── core.js (core module)
│ ├── date/ (date source code)
│ ├── date.js (date module)
│ ├── translate.js (translate module)
│ └── util/ (basic JavaScript helpers polyfills, eg array.map)
└── test/ (unit and functional test files)
├── fixtures/ (CLDR fixture data)
├── functional/ (functional tests)
├── functional.html
├── functional.js
├── unit/ (unit tests)
├── unit.html
└── unit.js
```
<a name="dates"></a>
<h2 id="dates">Date Formatting</h2>
<p>
Date formatting varies wildly by culture, not just in the spelling of month and
day names, and the date separator, but by the expected order of the various
date components, whether to use a 12 or 24 hour clock, and how months and days
are abbreviated. Many cultures even include "genitive" month names, which are
different from the typical names and are used only in certain cases.
</p>
<p>
Also, each culture has a set of "standard" or "typical" formats. For example,
in "en-US", when displaying a date in its fullest form, it looks like
"Saturday, November 05, 1955". Note the non-abbreviated day and month name, the
zero padded date, and four digit year. So, Globalize expects a certain set
of "standard" formatting strings for dates in the "patterns" property of the
"standard" calendar of each culture, that describe specific formats for the
culture. The third column shows example values in the neutral English culture
"en-US"; see the second table for the meaning tokens used in date formats.
<a name="source_files"></a>
### Source files
<pre>
// just for example - will vary by culture
Globalize.format( new Date(2012, 1, 20), 'd' ); // 2/20/2012
Globalize.format( new Date(2012, 1, 20), 'D' ); // Monday, February 20, 2012
</pre>
<p>
The source files are as granular as possible. When combined to generate the
build file, all the excessive/overhead wrappers are cut off. It's following
the same build model of jQuery and Modernizr.
</p>
<table>
<tr>
<th>Format</th>
<th>Meaning</th>
<th>"en-US"</th>
</tr>
<tr>
<td>f</td>
<td>Long Date, Short Time</td>
<td>dddd, MMMM dd, yyyy h:mm tt</td>
</tr>
<tr>
<td>F</td>
<td>Long Date, Long Time</td>
<td>dddd, MMMM dd, yyyy h:mm:ss tt</td>
</tr>
<tr>
<td>t</td>
<td>Short Time</td>
<td>h:mm tt</td>
</tr>
<tr>
<td>T</td>
<td>Long Time</td>
<td>h:mm:ss tt</td>
</tr>
<tr>
<td>d</td>
<td>Short Date</td>
<td>M/d/yyyy</td>
</tr>
<tr>
<td>D</td>
<td>Long Date</td>
<td>dddd, MMMM dd, yyyy</td>
</tr>
<tr>
<td>Y</td>
<td>Month/Year</td>
<td>MMMM, yyyy</td>
</tr>
<tr>
<td>M</td>
<td>Month/Day</td>
<td>MMMM dd</td>
</tr>
</table>
</p>
<p>
In addition to these standard formats, there is the "S" format. This is a
sortable format that is identical in every culture:
"<strong>yyyy'-'MM'-'dd'T'HH':'mm':'ss</strong>".
</p>
<p>
When more specific control is needed over the formatting, you may use any
format you wish by specifying the following custom tokens:
<table>
<tr>
<th>Token</th>
<th>Meaning</th>
<th>Example</th>
</tr>
<tr>
<td>d</td>
<td>Day of month (no leading zero)</td>
<td>5</td>
</tr>
<tr>
<td>dd</td>
<td>Day of month (leading zero)</td>
<td>05</td>
</tr>
<tr>
<td>ddd</td>
<td>Day name (abbreviated)</td>
<td>Sat</td>
</tr>
<tr>
<td>dddd</td>
<td>Day name (full)</td>
<td>Saturday</td>
</tr>
<tr>
<td>M</td>
<td>Month of year (no leading zero)</td>
<td>9</td>
</tr>
<tr>
<td>MM</td>
<td>Month of year (leading zero)</td>
<td>09</td>
</tr>
<tr>
<td>MMM</td>
<td>Month name (abbreviated)</td>
<td>Sep</td>
</tr>
<tr>
<td>MMMM</td>
<td>Month name (full)</td>
<td>September</td>
</tr>
<tr>
<td>yy</td>
<td>Year (two digits)</td>
<td>55</td>
</tr>
<tr>
<td>yyyy</td>
<td>Year (four digits)</td>
<td>1955</td>
</tr>
<tr>
<td>'literal'</td>
<td>Literal Text</td>
<td>'of the clock'</td>
</tr>
<tr>
<td>\'</td>
<td>Single Quote</td>
<td>'o'\''clock'</td><!-- o'clock -->
</tr>
<tr>
<td>m</td>
<td>Minutes (no leading zero)</td>
<td>9</td>
</tr>
<tr>
<td>mm</td>
<td>Minutes (leading zero)</td>
<td>09</td>
</tr>
<tr>
<td>h</td>
<td>Hours (12 hour time, no leading zero)</td>
<td>6</td>
</tr>
<tr>
<td>hh</td>
<td>Hours (12 hour time, leading zero)</td>
<td>06</td>
</tr>
<tr>
<td>H</td>
<td>Hours (24 hour time, no leading zero)</td>
<td>5 (5am) 15 (3pm)</td>
</tr>
<tr>
<td>HH</td>
<td>Hours (24 hour time, leading zero)</td>
<td>05 (5am) 15 (3pm)</td>
</tr>
<tr>
<td>s</td>
<td>Seconds (no leading zero)</td>
<td>9</td>
</tr>
<tr>
<td>ss</td>
<td>Seconds (leading zero)</td>
<td>09</td>
</tr>
<tr>
<td>f</td>
<td>Deciseconds</td>
<td>1</td>
</tr>
<tr>
<td>ff</td>
<td>Centiseconds</td>
<td>11</td>
</tr>
<tr>
<td>fff</td>
<td>Milliseconds</td>
<td>111</td>
</tr>
<tr>
<td>t</td>
<td>AM/PM indicator (first letter)</td>
<td>A or P</td>
</tr>
<tr>
<td>tt</td>
<td>AM/PM indicator (full)</td>
<td>AM or PM</td>
</tr>
<tr>
<td>z</td>
<td>Timezone offset (hours only, no leading zero)</td>
<td>-8</td>
</tr>
<tr>
<td>zz</td>
<td>Timezone offset (hours only, leading zero)</td>
<td>-08</td>
</tr>
<tr>
<td>zzz</td>
<td>Timezone offset (full hours/minutes)</td>
<td>-08:00</td>
</tr>
<tr>
<td>g or gg</td>
<td>Era name</td>
<td>A.D.</td>
</tr>
</table>
</p>
Core, and all modules' public APIs are located in the `src/` directory. For
example: `core.js`, `date.js`, and `translate.js`.
<a name="generating"></a>
<h1 id="generating">Generating Culture Files</h1>
<a name="build"></a>
### Build
The Globalize culture files are generated JavaScript containing metadata and
functions based on culture info in the Microsoft .Net Framework 4.
Install Grunt and external dependencies. First, install the
[grunt-cli](http://gruntjs.com/getting-started#installing-the-cli) and
[bower](http://bower.io/) packages if you haven't before. These should be installed
globally (like this: `npm install -g grunt-cli bower`). Then:
<h2>Requirements</h2>
```bash
npm install && bower install
```
<ul>
<li>Windows</li>
<li>Microsoft .Net Framework 4 (Full, not just Client Profile) <a href="http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&FamilyID=0a391abd-25c1-4fc0-919f-b21f31ab88b7">download dotNetFx40_Full_x86_x64.exe</a></li>
</ul>
Build distribution files.
```bash
grunt
```
<h2>Building the generator</h2>
<a name="tests"></a>
### Tests
1. Open a Windows Command Prompt ( Start -> Run... -> cmd )
1. Change directory to root of Globalize project (where README.md file is located)
1. >"C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild" generator\generator.csproj
Tests can be run either in the browser or using Node.js (via Grunt).
<h2>Running the generator</h2>
***Unit tests***
1. Open a Windows Command Prompt
1. Change directory to root of Globalize project (where README.md file is located)
1. >"generator\bin\Debug\generator.exe"
To run the unit tests, run `grunt test:unit`, or open
`file:///.../globalize/test/unit.html` in a browser. It tests the very specific functionality
of each function (sometimes internal/private).
<a name="building"></a>
<h1 id="building">Building Globalize</h1>
The goal of the unit tests is to make it easy to spot bugs, easy to debug.
Globalize is built using <a href="https://github.com/cowboy/grunt">grunt</a>, a
node-based build utility. First, make sure grunt is installed globally:
***Functional tests***
<pre>
> npm install -g grunt
</pre>
To run the functional tests, create the dist files by running `grunt`. Then, run
`grunt test:functional`, or open
`file:///.../globalize/test/functional.html` in a browser. Note that `grunt` will
automatically run unit and functional tests for you to ensure the built files
are safe.
then you can lint and test by simply running grunt in the globalize folder
<pre>
> cd globalize
> grunt
</pre>
The goal of the functional tests is to ensure that everything works as expected when it is combined.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc