



var Translation = {
	
	data: {},
	
	kw: function(keyword) {
		
		switch(typeof(keyword)) {
			case 'undefined':
				return null;
			case 'boolean':
				return null;
			case 'object':
				if (!keyword.toString) return null;
				keyword = keyword.toString();
				break;
			default:
				keyword = String(keyword);
		}
		
		return keyword.replace(/[\s\t\-]+/g, '_');
	},
	
	set: function(translations) {
		
		
		
	},
	
	get: function(keyword) {
		keyword = this.kw(keyword);
		if (!keyword) return null;
		if (this.data[keyword]) return this.data[keyword];
		
		var path = window.location.href.replace($$('base').last().href, '');
				
		new Ajax.Request('/api/translate/get/' + keyword + '/' + path, {
			method: 'post',
			onSuccess: function(transport, json) {
				if (json && json.success) {
					this.add(keyword, transport.responseJSON)
				}
			}.bind(this)
		});
		
		return keyword;
	},
	
	add: function(keyword, translation) {
		keyword = this.kw(keyword);
		if (!keyword) return null;
		this.data[keyword] = translation;
	},
	
	translate: function(keyword) {
		var translation = this.get(keyword);
		if (translation) return translation;
		return keyword;
	}
}


Object.extend(String.prototype, {
	translate: function () {
		var translatedValue = Translation.translate(this);
		return translatedValue;
	}
	
});