Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ Step 2: every text you want translated include the trn class

<span class="trn">text to translate</span>

Step 2.1 Input and textarea placeholder translated include the trn class

<input type="text" class="trn" placeholder="text to translate" />

<textarea class="trn" placeholder="text to translate"></textarea>

Step 3: create your dictionary

var dict = {
Expand Down
25 changes: 19 additions & 6 deletions jquery.translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
* @license MIT license <http://www.opensource.org/licenses/MIT>
*
* translate.js is a jQuery plugin to translate text in the client side.
*
* Added input and textarea placeholder support
* @author Hakan Torun
* @site hakan.io
*/

(function($){
Expand Down Expand Up @@ -68,12 +70,23 @@
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

if($this.is('input') || $this.is('textarea')){

if (!trn_key) {
trn_key = $this.attr("placeholder");
$this.attr("data-trn-key", trn_key); //store key for next time
}
$this.attr("placeholder",that.get(trn_key));
}
else{
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));
}

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


Expand All @@ -82,4 +95,4 @@


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