PageSourceSearch

https://www.mysubaru.com/asset/_lib/translate-master/jquery.translate.js

js mysubaru.com collected 2026-09-24 11:49:37 UTC 3,496 bytes, 115 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    var settings = {
18      css: "trn",
19      lang: "en"/*,
20      t: {
21        "translate": {
22          pt: "tradução",
23          br: "tradução"
24        }
25      }*/
26    };
27    settings = $.extend(settings, options || {});
28    if (settings.css.lastIndexOf(".", 0) !== 0)   //doesn't start with '.'
29      settings.css = "." + settings.css;
30       
31    var t = settings.t;
32 
33    //public methods
34    this.lang = function(l) {
35      if (l) {
36        settings.lang = l;
37        this.translate(settings);  //translate everything
38      }
39        
40      return settings.lang;
41    };
42
43
44    this.get = function(index) {
45      var res = index;
46      try {
47        //res = t[index.split("_")[0]][index.split("_")[1]][settings.lang];  //modified to access the second level of object for translation
48        res = t[index.split(".")[0]][index.split(".")[1]];  //remove "en" from translate obj, replace "_" with "."
49      }
50      catch (err) {
51        //not found, return index
52        return index;
53      }
54      
55      if (res)
56        return res;
57      else
58        return index;
59    };
60
61    this.g = this.get;
62
63
64    
65    //main
66    this.find(settings.css).each(function(i) {
67      var $this = $(this);
68
69      var trn_key = $this.attr("data-trn-key");
70      if (!trn_key) {
71        trn_key = $this.html() ? $this.html() : undefined;
72        $this.attr("data-trn-key", trn_key);   //store key for next time
73      }
74
75      var trn_value = $this.attr("data-trn-value"); // Translate attribute value="" (e.g = submit button)
76      if (!trn_value) {
77        trn_value = $this.val() ? $this.val() : undefined;
78        $this.attr("data-trn-value", trn_value);   //store key for next time
79      }
80
81      var trn_holder = $this.attr("data-trn-holder"); // Translate attribute placeholder="" (e.g = input text field)
82      if (!trn_holder) {
83        trn_holder = $(this).data("placeholder");
84        $this.attr("data-trn-holder", trn_holder);   //store key for next time
85      }
86
87      var trn_title = $this.attr("data-trn-title"); // Translate attribute title=""
88      if (!trn_title) {
89        trn_title = $(this).data("data-title");
90        $this.attr("data-trn-title", trn_title);   //store key for next time
91      }
92
93      var trn_tip = $this.attr("data-trn-tip"); // Translate attribute data-tip=""
94      if (!trn_tip) {
95        trn_tip = $(this).data("data-tip");
96        $this.attr("data-trn-tip", trn_tip);   //store key for next time
97      }
98
99      var trn_alt = $this.attr("data-trn-alt"); // Translate attribute alt
100      if (!trn_alt) {
101        trn_alt = $(this).data("alt");
102        $this.attr("data-trn-alt", trn_alt);   //store key for next time
103      }
104
105      $this.html(that.get(trn_key)); // plain text html
106      $this.val(that.get(trn_value)); // attribute value
107      $(this).attr("placeholder", that.get(trn_holder)); // attribute placeholder
108      $(this).attr("data-title", that.get(trn_title)); // attribute title
109      $(this).attr("data-tip", that.get(trn_tip)); // attribute data-tip
110      $(this).attr("alt", that.get(trn_alt)); // attribute alt
111
112    });
113		return this;
114  };
115})(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.