tinoni / translate.js

A jQuery plugin to translate text in the client side
MIT License
87 stars 84 forks source link

Placeholders translation. #10

Closed umimehar closed 3 years ago

umimehar commented 7 years ago

I was in need to translate the placeholder too. so i made this snippet of code.

  for (var i = 0; i < $(".trn").get().length; i++) {
  if ($(".trn").get()[i].nodeName == "INPUT") {
    var placeholderValue = $($(".trn").get()[i]).attr("placeholder");

    var trn_key = $($(".trn").get()[i]).attr("data-trn-key");
    if (!trn_key) {
      trn_key = placeholderValue;
      $($(".trn").get()[i]).attr("data-trn-key", trn_key);   //store key for next time
    }
    $($(".trn").get()[i]).attr("placeholder", t[trn_key][settings.lang]);

  }

} 
JeanPaiva42 commented 6 years ago

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 } if($this.nodeName === 'INPUT'){ var placeholderValue = $this.attr("placeholder"); $this.attr("placeholder", that.get(placeholderValue)); } $this.html(that.get(trn_key)); });

umimehar commented 3 years ago

https://github.com/umimehar/translateAll.jquery.js i have created this fork for translate every thing on DOM :)