Ext.namespace('Voyeur.Localization');

Voyeur.Localization = function(lang) {	
	this.lang = lang ? lang : 'en';
	this.bundle = new Ext.util.MixedCollection();
}

Voyeur.Localization.prototype = {
	
	/**
	 * Load the values from the passed object into the resource bundle.
	 * @param {Object} json
	 */
	load : function(json) {
		this.bundle.addAll(json);
	},
	
	/**
	 * Retrieve the localized object from the specified key and language (if no
	 * lang parameter is specified, the default one for this instance is used).
	 * @param {String} key the key
	 * @param {String} lang (optional) override the default language
	 */
	get : function(key,lang) {
		lang = lang ? lang : this.lang;
		var vals = this.bundle.get(key);
		if (!vals) {return key;} // key value doesn't exist, return key
		if (vals.lang) {return vals.lang;} // key value returns for lang, return it
		if (vals.en) {return vals.en;} // key value returns for English, return it
		for (var k in vals) {return vals[k]} // return the first value that exists
	}
	
	/**
	 * Get the current two-letter language code.
	 */
	,getLang: function() {
		return this.lang;
	}
}

Voyeur.localization = new Voyeur.Localization();
