tr8n 3.2.2 → 3.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +1 -1
- data/lib/tr8n/version.rb +1 -1
- data/tr8n.gemspec +2 -2
- metadata +41 -117
- data/app/javascript/compile.rb +0 -37
- data/app/javascript/compile.sh +0 -1
- data/app/javascript/compressors/google/COPYING +0 -202
- data/app/javascript/compressors/google/README +0 -292
- data/app/javascript/compressors/google/compiler.jar +0 -0
- data/app/javascript/config.yml +0 -66
- data/app/javascript/src/base.js +0 -35
- data/app/javascript/src/effects.js +0 -67
- data/app/javascript/src/ext/inflector.js +0 -309
- data/app/javascript/src/ext/jsDraw2D.js +0 -24
- data/app/javascript/src/ext/keyboard_1_36.js +0 -1214
- data/app/javascript/src/ext/keyboard_1_44.js +0 -1735
- data/app/javascript/src/ext/keyboard_1_49.js +0 -1796
- data/app/javascript/src/ext/md5.js +0 -209
- data/app/javascript/src/ext/shortcut.js +0 -223
- data/app/javascript/src/init.js +0 -47
- data/app/javascript/src/language.js +0 -38
- data/app/javascript/src/logger.js +0 -203
- data/app/javascript/src/prototype/effects.js +0 -65
- data/app/javascript/src/proxy.js +0 -254
- data/app/javascript/src/rules/date_rule.js +0 -37
- data/app/javascript/src/rules/gender_list_rule.js +0 -37
- data/app/javascript/src/rules/gender_rule.js +0 -87
- data/app/javascript/src/rules/language_rule.js +0 -55
- data/app/javascript/src/rules/list_rule.js +0 -37
- data/app/javascript/src/rules/numeric_rule.js +0 -95
- data/app/javascript/src/tml/label.js +0 -60
- data/app/javascript/src/tml/token.js +0 -107
- data/app/javascript/src/tokens/data_token.js +0 -45
- data/app/javascript/src/tokens/decoration_token.js +0 -82
- data/app/javascript/src/tokens/token.js +0 -121
- data/app/javascript/src/tokens/transform_token.js +0 -106
- data/app/javascript/src/translation_key.js +0 -183
- data/app/javascript/src/ui/language_case_manager.js +0 -155
- data/app/javascript/src/ui/language_selector.js +0 -126
- data/app/javascript/src/ui/lightbox.js +0 -72
- data/app/javascript/src/ui/translator.js +0 -257
- data/app/javascript/src/utils.js +0 -286
@@ -1,45 +0,0 @@
|
|
1
|
-
/****************************************************************************
|
2
|
-
Copyright (c) 2010-2012 Michael Berkovich, Ian McDaniel, tr8n.net
|
3
|
-
|
4
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
-
a copy of this software and associated documentation files (the
|
6
|
-
"Software"), to deal in the Software without restriction, including
|
7
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
-
permit persons to whom the Software is furnished to do so, subject to
|
10
|
-
the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be
|
13
|
-
included in all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
-
****************************************************************************/
|
23
|
-
|
24
|
-
Tr8n.Proxy.DataToken = function(label, token, options) {
|
25
|
-
this.label = label;
|
26
|
-
this.full_name = token;
|
27
|
-
this.options = options;
|
28
|
-
}
|
29
|
-
|
30
|
-
Tr8n.Proxy.DataToken.prototype = new Tr8n.Proxy.Token();
|
31
|
-
|
32
|
-
Tr8n.Proxy.DataToken.parse = function(label, options) {
|
33
|
-
var tokens = label.match(/(\{[^_][\w]+(:[\w]+)?\})/g);
|
34
|
-
if (!tokens) return [];
|
35
|
-
|
36
|
-
var objects = [];
|
37
|
-
var uniq = {};
|
38
|
-
for(i=0; i<tokens.length; i++) {
|
39
|
-
if (uniq[tokens[i]]) continue;
|
40
|
-
options['proxy'].debug("Registering data token: " + tokens[i]);
|
41
|
-
objects.push(new Tr8n.Proxy.DataToken(label, tokens[i], options));
|
42
|
-
uniq[tokens[i]] = true;
|
43
|
-
}
|
44
|
-
return objects;
|
45
|
-
}
|
@@ -1,82 +0,0 @@
|
|
1
|
-
/****************************************************************************
|
2
|
-
Copyright (c) 2010-2012 Michael Berkovich, Ian McDaniel, tr8n.net
|
3
|
-
|
4
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
-
a copy of this software and associated documentation files (the
|
6
|
-
"Software"), to deal in the Software without restriction, including
|
7
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
-
permit persons to whom the Software is furnished to do so, subject to
|
10
|
-
the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be
|
13
|
-
included in all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
-
****************************************************************************/
|
23
|
-
|
24
|
-
Tr8n.Proxy.DecorationToken = function(label, token, options) {
|
25
|
-
this.label = label;
|
26
|
-
this.full_name = token;
|
27
|
-
this.options = options;
|
28
|
-
}
|
29
|
-
|
30
|
-
Tr8n.Proxy.DecorationToken.prototype = new Tr8n.Proxy.Token();
|
31
|
-
|
32
|
-
Tr8n.Proxy.DecorationToken.parse = function(label, options) {
|
33
|
-
var tokens = label.match(/(\[\w+:[^\]]+\])/g);
|
34
|
-
if (!tokens) return [];
|
35
|
-
|
36
|
-
var objects = [];
|
37
|
-
var uniq = {};
|
38
|
-
for(i=0; i<tokens.length; i++) {
|
39
|
-
if (uniq[tokens[i]]) continue;
|
40
|
-
options['proxy'].debug("Registering decoration token: " + tokens[i]);
|
41
|
-
objects.push(new Tr8n.Proxy.DecorationToken(label, tokens[i], options));
|
42
|
-
uniq[tokens[i]] = true;
|
43
|
-
}
|
44
|
-
return objects;
|
45
|
-
}
|
46
|
-
|
47
|
-
Tr8n.Proxy.DecorationToken.prototype.getDecoratedValue = function() {
|
48
|
-
if (!this.decorated_value) {
|
49
|
-
var value = this.getFullName().replace(/[\]]/g, '');
|
50
|
-
value = value.substring(value.indexOf(':') + 1, value.length);
|
51
|
-
this.decorated_value = Tr8n.Utils.trim(value);
|
52
|
-
}
|
53
|
-
return this.decorated_value;
|
54
|
-
}
|
55
|
-
|
56
|
-
Tr8n.Proxy.DecorationToken.prototype.substitute = function(label, token_values) {
|
57
|
-
var object = token_values[this.getName()];
|
58
|
-
var decoration = object;
|
59
|
-
|
60
|
-
if (!object || typeof object == 'object') {
|
61
|
-
// look for the default decoration
|
62
|
-
decoration = this.getProxy().getDecorationFor(this.getName());
|
63
|
-
if (!decoration) {
|
64
|
-
this.getLogger().error("Default decoration is not defined for token " + this.getName());
|
65
|
-
return label;
|
66
|
-
}
|
67
|
-
|
68
|
-
decoration = Tr8n.Utils.replaceAll(decoration, '{$0}', this.getDecoratedValue());
|
69
|
-
if (object) {
|
70
|
-
for (var key in object) {
|
71
|
-
decoration = Tr8n.Utils.replaceAll(decoration, '{$' + key + '}', object[key]);
|
72
|
-
}
|
73
|
-
}
|
74
|
-
} else if (typeof object == 'string') {
|
75
|
-
decoration = Tr8n.Utils.replaceAll(decoration, '{$0}', this.getDecoratedValue());
|
76
|
-
} else {
|
77
|
-
this.getLogger().error("Unknown type of decoration token " + this.getFullName());
|
78
|
-
return label;
|
79
|
-
}
|
80
|
-
|
81
|
-
return Tr8n.Utils.replaceAll(label, this.getFullName(), decoration);
|
82
|
-
}
|
@@ -1,121 +0,0 @@
|
|
1
|
-
/****************************************************************************
|
2
|
-
Copyright (c) 2010-2012 Michael Berkovich, Ian McDaniel, tr8n.net
|
3
|
-
|
4
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
-
a copy of this software and associated documentation files (the
|
6
|
-
"Software"), to deal in the Software without restriction, including
|
7
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
-
permit persons to whom the Software is furnished to do so, subject to
|
10
|
-
the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be
|
13
|
-
included in all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
-
****************************************************************************/
|
23
|
-
|
24
|
-
Tr8n.Proxy.Token = function() {}
|
25
|
-
|
26
|
-
Tr8n.Proxy.Token.prototype = {
|
27
|
-
getProxy: function() {
|
28
|
-
return this.options['proxy'];
|
29
|
-
},
|
30
|
-
getLogger: function() {
|
31
|
-
return this.getProxy().logger;
|
32
|
-
},
|
33
|
-
getExpression: function() {
|
34
|
-
// must be implemented by the extending class
|
35
|
-
return null;
|
36
|
-
},
|
37
|
-
register: function(label, options) {
|
38
|
-
if (this.getExpression() == null)
|
39
|
-
alert("Token expression must be provided");
|
40
|
-
|
41
|
-
var tokens = label.match(this.getExpression());
|
42
|
-
if (!tokens) return [];
|
43
|
-
|
44
|
-
var objects = [];
|
45
|
-
var uniq = {};
|
46
|
-
for(i=0; i<tokens.length; i++) {
|
47
|
-
if (uniq[tokens[i]]) continue;
|
48
|
-
options['proxy'].debug("Registering data token: " + tokens[i]);
|
49
|
-
objects.push(new Tr8n.Proxy.TransformToken(label, tokens[i], options));
|
50
|
-
uniq[tokens[i]] = true;
|
51
|
-
}
|
52
|
-
return objects;
|
53
|
-
},
|
54
|
-
getFullName: function() {
|
55
|
-
return this.full_name;
|
56
|
-
},
|
57
|
-
getDeclaredName: function() {
|
58
|
-
if (!this.declared_name) {
|
59
|
-
this.declared_name = this.getFullName().replace(/[{}\[\]]/g, '');
|
60
|
-
}
|
61
|
-
return this.declared_name;
|
62
|
-
},
|
63
|
-
getName: function() {
|
64
|
-
if (!this.name) {
|
65
|
-
this.name = Tr8n.Utils.trim(this.getDeclaredName().split(':')[0]);
|
66
|
-
}
|
67
|
-
return this.name;
|
68
|
-
},
|
69
|
-
getLanguageRule: function() {
|
70
|
-
|
71
|
-
return null;
|
72
|
-
},
|
73
|
-
substitute: function(label, token_values) {
|
74
|
-
var value = token_values[this.getName()];
|
75
|
-
|
76
|
-
if (value == null) {
|
77
|
-
this.getLogger().error("Value for token: " + this.getFullName() + " was not provided");
|
78
|
-
return label;
|
79
|
-
}
|
80
|
-
|
81
|
-
return Tr8n.Utils.replaceAll(label, this.getFullName(), this.getTokenValue(value));
|
82
|
-
},
|
83
|
-
getTokenValue: function(token_value) {
|
84
|
-
if (typeof token_value == 'string') return token_value;
|
85
|
-
if (typeof token_value == 'number') return token_value;
|
86
|
-
return token_value['value'];
|
87
|
-
},
|
88
|
-
getTokenObject: function(token_value) {
|
89
|
-
if (typeof token_value == 'string') return token_value;
|
90
|
-
if (typeof token_value == 'number') return token_value;
|
91
|
-
return token_value['subject'];
|
92
|
-
},
|
93
|
-
getType: function() {
|
94
|
-
if (this.getDeclaredName().indexOf(':') == -1)
|
95
|
-
return null;
|
96
|
-
|
97
|
-
if (!this.type) {
|
98
|
-
this.type = this.getDeclaredName().split('|')[0].split(':');
|
99
|
-
this.type = this.type[this.type.length - 1];
|
100
|
-
}
|
101
|
-
|
102
|
-
return this.type;
|
103
|
-
},
|
104
|
-
getSuffix: function() {
|
105
|
-
if (!this.suffix) {
|
106
|
-
this.suffix = this.getName().split('_');
|
107
|
-
this.suffix = this.suffix[this.suffix.length - 1];
|
108
|
-
}
|
109
|
-
return this.suffix;
|
110
|
-
},
|
111
|
-
getLanguageRule: function() {
|
112
|
-
if (!this.language_rule) {
|
113
|
-
if (this.getType()) {
|
114
|
-
this.language_rule = this.getProxy().getLanguageRuleForType(this.getType());
|
115
|
-
} else {
|
116
|
-
this.language_rule = this.getProxy().getLanguageRuleForTokenSuffix(this.getSuffix());
|
117
|
-
}
|
118
|
-
}
|
119
|
-
return this.language_rule;
|
120
|
-
}
|
121
|
-
}
|
@@ -1,106 +0,0 @@
|
|
1
|
-
/****************************************************************************
|
2
|
-
Copyright (c) 2010-2012 Michael Berkovich, Ian McDaniel, tr8n.net
|
3
|
-
|
4
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
-
a copy of this software and associated documentation files (the
|
6
|
-
"Software"), to deal in the Software without restriction, including
|
7
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
-
permit persons to whom the Software is furnished to do so, subject to
|
10
|
-
the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be
|
13
|
-
included in all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
-
****************************************************************************/
|
23
|
-
|
24
|
-
Tr8n.Proxy.TransformToken = function(label, token, options) {
|
25
|
-
this.label = label;
|
26
|
-
this.full_name = token;
|
27
|
-
this.options = options;
|
28
|
-
}
|
29
|
-
|
30
|
-
Tr8n.Proxy.TransformToken.prototype = new Tr8n.Proxy.Token();
|
31
|
-
|
32
|
-
Tr8n.Proxy.TransformToken.parse = function(label, options) {
|
33
|
-
var tokens = label.match(/(\{[^_][\w]+(:[\w]+)?\s*\|\|?[^{^}]+\})/g);
|
34
|
-
if (!tokens) return [];
|
35
|
-
|
36
|
-
var objects = [];
|
37
|
-
var uniq = {};
|
38
|
-
for(i=0; i<tokens.length; i++) {
|
39
|
-
if (uniq[tokens[i]]) continue;
|
40
|
-
options['proxy'].debug("Registering transform token: " + tokens[i]);
|
41
|
-
objects.push(new Tr8n.Proxy.TransformToken(label, tokens[i], options));
|
42
|
-
uniq[tokens[i]] = true;
|
43
|
-
}
|
44
|
-
return objects;
|
45
|
-
}
|
46
|
-
|
47
|
-
Tr8n.Proxy.TransformToken.prototype.getName = function() {
|
48
|
-
if (!this.name) {
|
49
|
-
this.name = Tr8n.Utils.trim(this.getDeclaredName().split('|')[0].split(':')[0]);
|
50
|
-
}
|
51
|
-
return this.name;
|
52
|
-
}
|
53
|
-
|
54
|
-
Tr8n.Proxy.TransformToken.prototype.getPipedParams = function() {
|
55
|
-
if (!this.piped_params) {
|
56
|
-
var temp = this.getDeclaredName().split('|');
|
57
|
-
temp = temp[temp.length - 1].split(",");
|
58
|
-
this.piped_params = [];
|
59
|
-
for (i=0; i<temp.length; i++) {
|
60
|
-
this.piped_params.push(Tr8n.Utils.trim(temp[i]));
|
61
|
-
}
|
62
|
-
}
|
63
|
-
return this.piped_params;
|
64
|
-
}
|
65
|
-
|
66
|
-
Tr8n.Proxy.TransformToken.prototype.substitute = function(label, token_values) {
|
67
|
-
var object = token_values[this.getName()];
|
68
|
-
if (object == null) {
|
69
|
-
this.getLogger().error("Value for token: " + this.getFullName() + " was not provided");
|
70
|
-
return label;
|
71
|
-
}
|
72
|
-
|
73
|
-
var token_object = this.getTokenObject(object);
|
74
|
-
this.getLogger().debug("Registered " + this.getPipedParams().length + " piped params");
|
75
|
-
|
76
|
-
var lang_rule_name = this.getLanguageRule();
|
77
|
-
|
78
|
-
if (!lang_rule_name) {
|
79
|
-
this.getLogger().error("Rule type cannot be determined for the transform token: " + this.getFullName());
|
80
|
-
return label;
|
81
|
-
} else {
|
82
|
-
this.getLogger().debug("Transform token uses rule: " + lang_rule_name);
|
83
|
-
}
|
84
|
-
|
85
|
-
var transform_value = eval(lang_rule_name).transform(token_object, this.getPipedParams());
|
86
|
-
this.getLogger().debug("Registered transform value: " + transform_value);
|
87
|
-
|
88
|
-
// for double pipes - show the actual value as well
|
89
|
-
if (this.isAllowedInTranslation()) {
|
90
|
-
var token_value = this.getTokenValue(object);
|
91
|
-
transform_value = token_value + " " + transform_value;
|
92
|
-
}
|
93
|
-
|
94
|
-
return Tr8n.Utils.replaceAll(label, this.getFullName(), transform_value);
|
95
|
-
}
|
96
|
-
|
97
|
-
Tr8n.Proxy.TransformToken.prototype.getPipedSeparator = function() {
|
98
|
-
if (!this.piped_separator) {
|
99
|
-
this.piped_separator = (this.getFullName().indexOf("||") != -1 ? "||" : "|");
|
100
|
-
}
|
101
|
-
return this.piped_separator;
|
102
|
-
}
|
103
|
-
|
104
|
-
Tr8n.Proxy.TransformToken.prototype.isAllowedInTranslation = function(){
|
105
|
-
return this.getPipedSeparator() == "||";
|
106
|
-
}
|
@@ -1,183 +0,0 @@
|
|
1
|
-
/****************************************************************************
|
2
|
-
Copyright (c) 2010-2012 Michael Berkovich, Ian McDaniel, tr8n.net
|
3
|
-
|
4
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
-
a copy of this software and associated documentation files (the
|
6
|
-
"Software"), to deal in the Software without restriction, including
|
7
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
-
permit persons to whom the Software is furnished to do so, subject to
|
10
|
-
the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be
|
13
|
-
included in all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
-
****************************************************************************/
|
23
|
-
|
24
|
-
Tr8n.Proxy.TranslationKey = function(label, description, options) {
|
25
|
-
this.label = label;
|
26
|
-
this.description = description;
|
27
|
-
this.options = options;
|
28
|
-
this.generateKey();
|
29
|
-
}
|
30
|
-
|
31
|
-
Tr8n.Proxy.TranslationKey.prototype = {
|
32
|
-
getProxy: function() {
|
33
|
-
return this.options['proxy'];
|
34
|
-
},
|
35
|
-
getLogger: function() {
|
36
|
-
return this.getProxy().logger;
|
37
|
-
},
|
38
|
-
findFirstAcceptableTranslation: function(translations, token_values) {
|
39
|
-
// check for a single translation case - no context rules
|
40
|
-
if (translations['label']!=null) {
|
41
|
-
this.getLogger().debug('Found a single translation: ' + translations['label']);
|
42
|
-
return translations;
|
43
|
-
}
|
44
|
-
|
45
|
-
translations = translations['labels'];
|
46
|
-
if (!translations) {
|
47
|
-
this.getLogger().error("Translations are in a weird form...");
|
48
|
-
return null;
|
49
|
-
}
|
50
|
-
|
51
|
-
this.getLogger().debug('Found translations: ' + translations.length);
|
52
|
-
for (var i=0; i<translations.length; i++) {
|
53
|
-
this.getLogger().debug("Checking context rules for:" + translations[i]['label']);
|
54
|
-
|
55
|
-
if (!translations[i]['context']) {
|
56
|
-
this.getLogger().debug("Translation has no context, using it by default");
|
57
|
-
return translations[i];
|
58
|
-
}
|
59
|
-
var valid_context = true;
|
60
|
-
|
61
|
-
for (var token in translations[i]['context']) {
|
62
|
-
if (!valid_context) continue;
|
63
|
-
var token_context = translations[i]['context'][token];
|
64
|
-
var rule_name = this.getProxy().getLanguageRuleForType(token_context['type']);
|
65
|
-
this.getLogger().debug("Evaluating rule: " + rule_name);
|
66
|
-
var options = {'proxy': this.getProxy()};
|
67
|
-
var rule = eval("new " + rule_name + "()");
|
68
|
-
rule.definition = token_context;
|
69
|
-
rule.options = options;
|
70
|
-
valid_context = valid_context && rule.evaluate(token, token_values);
|
71
|
-
}
|
72
|
-
|
73
|
-
if (valid_context) {
|
74
|
-
this.getLogger().debug("Found valid translation: " + translations[i].label);
|
75
|
-
return translations[i];
|
76
|
-
} else {
|
77
|
-
this.getLogger().debug("The rules were not matched for: " + translations[i].label);
|
78
|
-
}
|
79
|
-
}
|
80
|
-
|
81
|
-
this.getLogger().debug('No acceptable ranslations found');
|
82
|
-
return null;
|
83
|
-
},
|
84
|
-
|
85
|
-
translate: function(language, token_values, options) {
|
86
|
-
if (!this.label) {
|
87
|
-
this.getLogger().error('Label must always be provided for the translate method');
|
88
|
-
return '';
|
89
|
-
}
|
90
|
-
|
91
|
-
var translations = this.getProxy().getTranslations();
|
92
|
-
var translation_key = translations[this.key];
|
93
|
-
|
94
|
-
if (translation_key) {
|
95
|
-
this.getLogger().debug("Found translations, evaluating rules...");
|
96
|
-
|
97
|
-
this.id = translation_key.id;
|
98
|
-
this.original = translation_key.original;
|
99
|
-
var translation = this.findFirstAcceptableTranslation(translation_key, token_values);
|
100
|
-
|
101
|
-
if (translation) {
|
102
|
-
this.getLogger().debug("Found a valid match: " + translation.label);
|
103
|
-
return this.substituteTokens(translation['label'], token_values, options);
|
104
|
-
} else {
|
105
|
-
this.getLogger().debug("No valid match found, using default language");
|
106
|
-
return this.substituteTokens(this.label, token_values, options);
|
107
|
-
}
|
108
|
-
|
109
|
-
} else {
|
110
|
-
this.getLogger().debug("Translation not found, using default language");
|
111
|
-
}
|
112
|
-
|
113
|
-
this.getProxy().registerMissingTranslationKey(this, token_values, options);
|
114
|
-
this.getLogger().debug('No translation found. Using default...');
|
115
|
-
return this.substituteTokens(this.label, token_values, options);
|
116
|
-
},
|
117
|
-
|
118
|
-
generateKey: function() {
|
119
|
-
this.key = this.label + ";;;";
|
120
|
-
if (this.description) this.key = this.key + this.description;
|
121
|
-
|
122
|
-
this.getLogger().debug('Preparing label signature: ' + this.key);
|
123
|
-
this.key = MD5(this.key);
|
124
|
-
this.getLogger().debug('Label signature: ' + this.key);
|
125
|
-
},
|
126
|
-
|
127
|
-
registerDataTokens: function(label) {
|
128
|
-
this.data_tokens = [];
|
129
|
-
this.data_tokens = this.data_tokens.concat(Tr8n.Proxy.DataToken.parse(label, {'key': this, 'proxy':this.getProxy()}));
|
130
|
-
this.data_tokens = this.data_tokens.concat(Tr8n.Proxy.TransformToken.parse(label, {'key': this, 'proxy':this.getProxy()}));
|
131
|
-
},
|
132
|
-
|
133
|
-
registerDecorationTokens: function(label) {
|
134
|
-
this.decoration_tokens = [];
|
135
|
-
this.decoration_tokens = this.decoration_tokens.concat(Tr8n.Proxy.DecorationToken.parse(label, {'key': this, 'proxy':this.getProxy()}));
|
136
|
-
},
|
137
|
-
|
138
|
-
substituteTokens: function(label, token_values, options) {
|
139
|
-
this.registerDataTokens(label);
|
140
|
-
if (!this.data_tokens) return this.decorateLabel(label, options);
|
141
|
-
for (var i = 0; i < this.data_tokens.length; i++) {
|
142
|
-
label = this.data_tokens[i].substitute(label, token_values || {});
|
143
|
-
}
|
144
|
-
|
145
|
-
this.registerDecorationTokens(label);
|
146
|
-
if (!this.decoration_tokens) return label;
|
147
|
-
for (var i = 0; i < this.decoration_tokens.length; i++) {
|
148
|
-
label = this.decoration_tokens[i].substitute(label, token_values || {});
|
149
|
-
}
|
150
|
-
|
151
|
-
return this.decorateLabel(label, options);
|
152
|
-
},
|
153
|
-
|
154
|
-
decorateLabel: function(label, options){
|
155
|
-
options = options || {};
|
156
|
-
if (options['skip_decorations'])
|
157
|
-
return label;
|
158
|
-
|
159
|
-
html = [];
|
160
|
-
html.push("<tr8n ");
|
161
|
-
|
162
|
-
if (this.id)
|
163
|
-
html.push(" translation_key_id='" + this.id + "' ");
|
164
|
-
|
165
|
-
if (this.key)
|
166
|
-
html.push(" id='" + this.key + "' ");
|
167
|
-
|
168
|
-
var klasses = ['tr8n_translatable'];
|
169
|
-
|
170
|
-
if (this.original)
|
171
|
-
klasses.push('tr8n_not_translated');
|
172
|
-
else
|
173
|
-
klasses.push('tr8n_translated');
|
174
|
-
|
175
|
-
if (this.getProxy().inline_translations_enabled && this.id)
|
176
|
-
html.push(" class='" + klasses.join(' ') + "'");
|
177
|
-
|
178
|
-
html.push(">");
|
179
|
-
html.push(label);
|
180
|
-
html.push("</tr8n>");
|
181
|
-
return html.join("");
|
182
|
-
}
|
183
|
-
}
|