i18n.js 402 Bytes
Newer Older
1 2
window.gettext = function(s) { return s; };
window.ngettext = function(singular, plural, num) { return num == 1 ? singular : plural; };
3 4 5

function interpolate(fmt, obj, named) {
    if (named) {
6
        return fmt.replace(/%\(\w+\)s/g, function(match) { return String(obj[match.slice(2, -2)]); });
7
    } else {
8
        return fmt.replace(/%s/g, function(match) { return String(obj.shift()); });
9 10
    }
}