File tree Expand file tree Collapse file tree 1 file changed +84
-0
lines changed Expand file tree Collapse file tree 1 file changed +84
-0
lines changed Original file line number Diff line number Diff line change
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 : "ro" ,
21
+ t : {
22
+ "translate" : {
23
+ en : "translate"
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
+
47
+ try {
48
+ res = t [ index ] [ settings . lang ] ;
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 ( ) ;
72
+ $this . attr ( "data-trn-key" , trn_key ) ; //store key for next time
73
+ }
74
+
75
+ $this . html ( that . get ( trn_key ) ) ;
76
+ } ) ;
77
+
78
+
79
+ return this ;
80
+
81
+
82
+
83
+ } ;
84
+ } ) ( jQuery ) ;
You can’t perform that action at this time.
0 commit comments