Skip to content

Instantly share code, notes, and snippets.

@vinitkumar
Created March 30, 2014 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinitkumar/9876957 to your computer and use it in GitHub Desktop.
Save vinitkumar/9876957 to your computer and use it in GitHub Desktop.
/* gettext library */
var catalog = new Array();
function pluralidx(count) { return (count == 1) ? 0 : 1; }
function gettext(msgid) {
var value = catalog[msgid];
if (typeof(value) == 'undefined') {
return msgid;
} else {
return (typeof(value) == 'string') ? value : value[0];
}
}
function ngettext(singular, plural, count) {
value = catalog[singular];
if (typeof(value) == 'undefined') {
return (count == 1) ? singular : plural;
} else {
return value[pluralidx(count)];
}
}
function gettext_noop(msgid) { return msgid; }
function pgettext(context, msgid) {
var value = gettext(context + '\x04' + msgid);
if (value.indexOf('\x04') != -1) {
value = msgid;
}
return value;
}
function npgettext(context, singular, plural, count) {
var value = ngettext(context + '\x04' + singular, context + '\x04' + plural, count);
if (value.indexOf('\x04') != -1) {
value = ngettext(singular, plural, count);
}
return value;
}
function interpolate(fmt, obj, named) {
if (named) {
return fmt.replace(/%\(\w+\)s/g, function(match){return String(obj[match.slice(2,-2)])});
} else {
return fmt.replace(/%s/g, function(match){return String(obj.shift())});
}
}
/* formatting library */
var formats = new Array();
formats['DATETIME_INPUT_FORMATS'] = ['%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M', '%Y-%m-%d', '%m/%d/%Y %H:%M:%S', '%m/%d/%Y %H:%M', '%m/%d/%Y', '%m/%d/%y %H:%M:%S', '%m/%d/%y %H:%M', '%m/%d/%y', '%Y-%m-%d %H:%M:%S.%f'];
formats['SHORT_DATETIME_FORMAT'] = 'm/d/Y P';
formats['TIME_FORMAT'] = 'P';
formats['TIME_INPUT_FORMATS'] = ['%H:%M:%S', '%H:%M'];
formats['MONTH_DAY_FORMAT'] = 'F j';
formats['THOUSAND_SEPARATOR'] = ',';
formats['SHORT_DATE_FORMAT'] = 'm/d/Y';
formats['DATE_INPUT_FORMATS'] = ['%d/%m/%Y', '%d/%m/%y', '%Y-%m-%d'];
formats['YEAR_MONTH_FORMAT'] = 'F Y';
formats['NUMBER_GROUPING'] = '3';
formats['DECIMAL_SEPARATOR'] = '.';
formats['FIRST_DAY_OF_WEEK'] = '0';
formats['DATE_FORMAT'] = 'N j, Y';
formats['DATETIME_FORMAT'] = 'N j, Y, P';
function get_format(format_type) {
var value = formats[format_type];
if (typeof(value) == 'undefined') {
return format_type;
} else {
return value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment