Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 45 additions & 22 deletions jquery.translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
$.fn.translate = function(options) {

var that = this; //a reference to ourselves

var settings = {
css: "trn",
lang: "en"/*,
lang: "en",
tooltip: false,
langTooltip: "pt"/*,
t: {
"translate": {
pt: "tradução",
Expand All @@ -28,16 +30,16 @@
settings = $.extend(settings, options || {});
if (settings.css.lastIndexOf(".", 0) !== 0) //doesn't start with '.'
settings.css = "." + settings.css;

var t = settings.t;

//public methods
this.lang = function(l) {
if (l) {
settings.lang = l;
this.translate(settings); //translate everything
}

return settings.lang;
};

Expand All @@ -52,7 +54,7 @@
//not found, return index
return index;
}

if (res)
return res;
else
Expand All @@ -62,24 +64,45 @@
this.g = this.get;



//main
this.find(settings.css).each(function(i) {
var $this = $(this);
if(settings.tooltip === false) {
this.find(settings.css).each(function(i) {
var $this = $(this);

var trn_key = $this.attr("data-trn-key");
if (!trn_key) {
trn_key = $this.html();
$this.attr("data-trn-key", trn_key); //store key for next time
}

$this.html(that.get(trn_key));
});

return this;

} else {
$(settings.css).hover(function(){
$(this).css('cursor', 'pointer');

var index = $(this).data('trn-key');
res = t[index][settings.langTooltip];

$(this).attr('rel', 'tooltip');
$(this).attr('title', res);

$(this).tooltip({placement: 'bottom',trigger: 'manual'}).tooltip('show');

}, function(){
$(this).tooltip('destroy');

$(this).removeAttr('rel');
$(this).removeAttr('title');
});

}

var trn_key = $this.attr("data-trn-key");
if (!trn_key) {
trn_key = $this.html();
$this.attr("data-trn-key", trn_key); //store key for next time
}

$this.html(that.get(trn_key));
});


return this;



};
})(jQuery);
})(jQuery);