PageSourceSearch

https://bluedex.github.io/js/jquery.translate.js

js bluedex.github.io collected 2026-10-03 08:43:20 UTC 2,624 bytes, 103 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
5 * @site
6 * @version 0.9
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    };
22    settings = $.extend(settings, options || {});
23    if (settings.css.lastIndexOf(".", 0) !== 0)   //doesn't start with '.'
24      settings.css = "." + settings.css;
25
26    var t = settings.t;
27
28    //public methods
29    this.lang = function(l) {
30      if (l) {
31        settings.lang = l;
32        this.translate(settings);  //translate everything
33      }
34
35      return settings.lang;
36    };
37
38
39    this.get = function(index) {
40      var res = index;
41
42      try {
43        res = t[index][settings.lang];
44      }
45      catch (err) {
46        //not found, return index
47        return index;
48      }
49
50      if (res)
51        return res;
52      else
53        return index;
54    };
55
56    this.g = this.get;
57
58
59
60    //main
61    this.find(settings.css).each(function(i) {
62      var $this = $(this);
63
64      var trn_key = $this.attr("data-trn-key");
65      var trn_key_placeholder = $this.attr("data-trn-key-placeholder");
66      var trn_key_data_content = $this.attr("data-trn-key-data-content");
67      var trn_key_title = $this.attr("data-trn-key-title");
68
69      if ($this.attr("placeholder")) {
70        if (!trn_key_placeholder) {
71          trn_key_placeholder = $this.attr("placeholder");
72          $this.attr("data-trn-key-placeholder", trn_key_placeholder);   //store key for next time
73        }
74        $this.attr("placeholder", that.get(trn_key_placeholder));
75      }
76      if ($this.attr("data-content")) {
77        if (!trn_key_data_content) {
78          trn_key_data_content = $this.attr("data-content");
79          $this.attr("data-trn-key-data-content", trn_key_data_content);   //store key for next time
80        }
81        $this.attr("data-content", that.get(trn_key_data_content));
82      }
83      if ($this.attr("title")) {
84        if (!trn_key_title) {
85          trn_key_title = $this.attr("title");
86          $this.attr("data-trn-key-title", trn_key_title);   //store key for next time
87        }
88        $this.attr("title", that.get(trn_key_title));
89      }
90      if (!trn_key) {
91        trn_key = $this.html();
92        $this.attr("data-trn-key", trn_key);   //store key for next time
93      }
94      $this.html(that.get(trn_key));
95    });
96
97
98		return this;
99
100
101
102  };
103})(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.