// I18n is slightly modified version of babilu.js from Tore Darell

var I18n = I18n || (function() {
    // Replace {{foo}} with obj.foo
    function interpolate(string, object) {
        return string.replace(/\{\{([^}]+)\}\}/g, function() {
            return object[arguments[1]] || arguments[0];
        });
    };

    // Split "foo.bar" to ["foo", "bar"] if key is a string
    function keyToArray(key) {
        if(!key) {
            return [];
        }
        if(typeof key != "string") {
            return key;
        }
        return key.split('.');
    };

    // Looks up a translation using an array of strings where the last
    // is the key and any string before that define the scope. The
    // current locale is always prepended and does not need to be
    // provided. The second parameter is an array of strings used as
    // defaults if the key can not be found. If a key starts with ":"
    // it is used as a key for lookup.  This method does not perform
    // pluralization or interpolation.
    function lookup(keys, defaults) {
        var i = 0, value = I18n.translations;
        defaults = (typeof defaults === "string") ? [defaults] : (defaults || []);
        while(keys[i]) {
            value = value && value[keys[i]];
            i++;
        }
        if(value) {
            return value;
        } else {
            if(defaults.length === 0) {
                return null;
            } else if (defaults[0].substr(0,1) === ':') {
                return lookup(keys.slice(0, keys.length - 1).concat(keyToArray(defaults[0].substr(1))), defaults.slice(1));
            } else {
                return defaults[0];
            }
        }
    };

    // Returns other when 0 given
    function pluralize(value, count) {
        if(count === undefined) return value;
        return count === 1 ? value.one : value.other;
    };

    // Works mostly the same as the Ruby equivalent, except there are
    // no symbols in JavaScript, so keys are always strings. The only
    // time this makes a difference is when differentiating between
    // keys and values in the defaultValue option. Strings starting
    // with ":" will be considered to be keys and used for lookup,
    // while other strings are returned as-is.
    function translate(key, options) {
        if(typeof key != "string") {
            // Bulk lookup
            var a = [], i;
            for(i = 0; i < key.length; i++) {
                a.push(translate(key[i], options));
            }
            return a;
        } else {
            options = options || {};
            options.defaultValue = options.defaultValue || null;
            key = keyToArray(options.scope).concat(keyToArray(key));
            var value = lookup(key, options.defaultValue);
            if(typeof value !== "string" && value) {
                value = pluralize(value, options.count);
            }
            if(typeof value === "string") {
                value = interpolate(value, options);
            }
            return value;
        }
    }

    return {
        translate: translate,
        t: translate
    };
})();

I18n.locale = I18n.locale || "pl";
I18n.translations = I18n.translations || {"activerecord":{"errors":{"messages":{"blank":"nie mo\u017ce by\u0107 puste","invalid":"jest nieprawid\u0142owe","too_short":"jest za kr\u00f3tkie (minimalnie {{count}} znak\u00f3w)","odd":"musi by\u0107 nieparzyste","confirmation":"nie zgadza si\u0119 z potwierdzeniem","greater_than":"musi by\u0107 wi\u0119ksze ni\u017c {{count}}","too_long":"jest za d\u0142ugie (maksymalnie {{count}} znak\u00f3w)","even":"musi by\u0107 parzyste","greater_than_or_equal_to":"musi by\u0107 wi\u0119ksze lub r\u00f3wne {{count}}","inclusion":"nie znajduje si\u0119 na li\u015bcie dopuszczalnych warto\u015bci","record_invalid":"wpis nieprawid\u0142owy","equal_to":"musi by\u0107 r\u00f3wne {{count}}","empty":"nie mo\u017ce by\u0107 puste","less_than":"musie by\u0107 mniejsze ni\u017c {{count}}","accepted":"musi by\u0107 zaakceptowane","exclusion":"znajduje si\u0119 na li\u015bcie zabronionych warto\u015bci","wrong_length":"jest nieprawid\u0142owej d\u0142ugo\u015bci (powinna wynosi\u0107 {{count}} znak\u00f3w)","less_than_or_equal_to":"musi by\u0107 mniejsze lub r\u00f3wne {{count}}","taken":"zosta\u0142o ju\u017c zaj\u0119te","not_a_number":"nie jest liczb\u0105"},"template":{"header":{"one":"{{model}} nie zosta\u0142 zachowany z powodu jednego b\u0142\u0119du","other":"{{model}} nie zosta\u0142 zachowany z powodu {{count}} b\u0142\u0119d\u00f3w"},"body":"B\u0142\u0119dy dotycz\u0105 nast\u0119puj\u0105cych p\u00f3l:"}}},"number":{"human":{"format":{"delimiter":"","precision":1},"storage_units":{"format":"%n %u","units":{"gb":"GB","byte":{"one":"bajt","other":"bajty"},"tb":"TB","kb":"KB","mb":"MB"}}},"format":{"separator":",","delimiter":" ","precision":2},"percentage":{"format":{"delimiter":""}},"currency":{"format":{"format":"%n %u","unit":"PLN"}},"precision":{"format":{"delimiter":""}}},"admin":{"notifications":{"order":{"paid":"Zam\u00f3wienie zosta\u0142o op\u0142acone","inprogress":"Zam\u00f3wienie jest w trakcie realizacji","placed":"Zam\u00f3wienie zosta\u0142o z\u0142o\u017cone","cancelled":"Zam\u00f3wienie zosta\u0142o anulowane","sent":"Zam\u00f3wienie zosta\u0142o wys\u0142ane","confirmed":"Zam\u00f3wienie zosta\u0142o potwierdzone"}}},"time":{"am":"przed po\u0142udniem","pm":"po po\u0142udniu","formats":{"long":"%d %B %Y, %H:%M","short":"%d %b, %H:%M","default":"%a, %d %b %Y, %H:%M:%S %z"}},"support":{"array":{"sentence_connector":"i","skip_last_comma":true}},"mail":{"placed":"Zam\u00f3wienie #{{order_id}} zosta\u0142o z\u0142o\u017cone","sent":"Zam\u00f3wienie #{{order_id}} zosta\u0142o wys\u0142ane","confirmed":"Zam\u00f3wienie #{{order_id}} zosta\u0142o potwierdzone","reminder":"Przypomnienie o zam\u00f3wieniu #{{order_id}}"},"columns":{"availability":"Dost\u0119pno\u015b\u0107","price":"Cena","image":"Obraz","parent":"Rodzic","buy":"Kup","available":"Dost\u0119pna","in_stock":"Stock","our_cost_brutto":"Nasz koszt brutto","title_pl":"Nazwa PL","description_en":"Opis EN","description_pl":"Opis PL","category":"Kategoria","parent_id":"ID 'rodzica'","code":"Kod","our_cost":"Nasz koszt (brutto)","name_en":"Nazwa EN","actions":"Akcje","name":"Nazwa","name_pl":"Nazwa PL","our_cost_netto":"Nasz koszt netto","id":"Id","added":"Dodano","title_en":"Nazwa EN"},"date":{"day_names":["Niedziela","Poniedzia\u0142ek","Wtorek","\u015aroda","Czwartek","Pi\u0105tek","Sobota"],"abbr_month_names":[null,"sty","lut","mar","kwi","maj","cze","lip","sie","wrz","pa\u017a","lis","gru"],"month_names":[null,"Stycze\u0144","Luty","Marzec","Kwiecie\u0144","Maj","Czerwiec","Lipiec","Sierpie\u0144","Wrzesie\u0144","Pa\u017adziernik","Listopad","Grudzie\u0144"],"abbr_day_names":["nie","pon","wto","\u015bro","czw","pia","sob"],"formats":{"long":"%d %B %Y","short":"%d %b","default":"%Y-%m-%d"},"order":["year","month","day"]},"will_paginate":{"next":"Nast\u0119pna","previous":"Poprzednia"},"datetime":{"distance_in_words":{"x_seconds":{"one":"sekund\u0119","few":"{{count}} sekundy","other":"{{count}} sekund"},"half_a_minute":"p\u00f3\u0142 minuty","about_x_hours":{"one":"oko\u0142o godziny","other":"about {{count}} godzin"},"about_x_years":{"one":"oko\u0142o roku","other":"oko\u0142o {{count}} lat"},"x_days":{"one":"1 dzie\u0144","other":"{{count}} dni"},"less_than_x_minutes":{"one":"mniej ni\u017c minut\u0119","few":"mniej ni\u017c {{count}} minuty","other":"mniej ni\u017c {{count}} minut"},"over_x_years":{"one":"ponad rok","few":"ponad {{count}} lata","other":"ponad {{count}} lat"},"about_x_months":{"one":"oko\u0142o miesi\u0105ca","other":"oko\u0142o {{count}} miesi\u0119cy"},"x_minutes":{"one":"minut\u0119","few":"{{count}} minuty","other":"{{count}} minut"},"x_months":{"one":"1 miesi\u0105c","few":"{{count}} miesi\u0105ce","other":"{{count}} miesi\u0119cy"},"less_than_x_seconds":{"one":"mniej ni\u017c sekund\u0119","few":"mniej ni\u017c {{count}} sekundy","other":"mniej ni\u017c {{count}} sekund"}}},"actions":{"add_to_cart":"Dodaj do koszyka","none_in_stock":"Brak","delete":"Skasuj","edit":"Edytuj","remove":"Usu\u0144","add":"Dodaj","save":"Zapisz"},"notifications":{"incorrect_order_id":"Nieprawid\u0142owy numer zam\u00f3wienia","unknown_product":"Nie ma takiego produktu","adding":"dodaj\u0119...","added_to_cart":"Dodano do koszyka","empty_cart":"Tw\u00f3j koszyk jest pusty","incorrect_order_password":"Nieprawid\u0142owe has\u0142o do zam\u00f3wienia"}};
