PageSourceSearch

https://hanfa.hr/scripts/jquery.translate.1.1.0.js

js hanfa.hr collected 2026-10-02 04:23:32 UTC 2,308 bytes, 97 lines download raw bytes

1/**
2 * @file jquery.translate.js
3 * @brief jQuery plugin to translate text in the client side.
4 * @author Manuel Fernandes (Original), Andy Dunkel (extensions)
5 * @site
6 * @version 1.1
7 * @license MIT license <http://www.opensource.org/licenses/MIT>
8 *
9 * translate.js is a jQuery plugin to translate text in the client side.
10 *
11 */
12
13(function($){
14  $.fn.translate = function(options) {
15
16    var that = this; //a reference to ourselves
17	
18    var settings = {
19      css: "trn",
20      lang: "en"/*,
21      t: {
22        "translate": {
23          pt: "tradução",
24          br: "tradução"
25        }
26      }*/
27    };
28    settings = $.extend(settings, options || {});
29    if (settings.css.lastIndexOf(".", 0) !== 0)   //doesn't start with '.'
30      settings.css = "." + settings.css;
31       
32    var t = settings.t;
33 
34    //public methods
35    this.lang = function(l) {
36      if (l) {
37        settings.lang = l;
38        this.translate(settings);  //translate everything
39      }
40        
41      return settings.lang;
42    };
43
44
45    this.get = function(index) {
46      var res = index;
47
48      try {
49        res = t[index][settings.lang];
50      }
51      catch (err) {
52        //not found, return index
53        return index;
54      }
55      
56      if (res)
57        return res;
58      else
59        return index;
60    };
61
62    this.g = this.get;
63
64    this.attribute = function(element, attrName) {
65      if (element.attr(attrName) !== undefined) {
66        let key = "data-trn-" + attrName + "-key";
67        let trn_attr_key = element.attr(key);
68        if (!trn_attr_key) {
69          trn_attr_key = element.attr(attrName); 
70          element.attr(key, trn_attr_key); //store key for next time
71        }
72
73        element.attr(attrName, that.get(trn_attr_key));
74      }
75    }
76    
77    //main
78    this.find(settings.css).each(function(i) {
79      let $this = $(this);
80
81      let trn_key = $this.attr("data-trn-key");
82      if (!trn_key) {
83        trn_key = $this.html();
84        $this.attr("data-trn-key", trn_key);   //store key for next time
85      }
86
87      $this.html(that.get(trn_key));
88 
89      //additional attributes
90      that.attribute($this, "title");
91	  that.attribute($this, "value");
92
93    });
94
95		return this;		
96  };
97})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.