tr8n 3.2.0 → 3.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +3 -1
- data/app/assets/javascripts/tr8n/tr8n-compiled.js +336 -0
- data/app/assets/stylesheets/tr8n/admin.css.scss +23 -0
- data/app/assets/stylesheets/tr8n/components.css.scss +23 -0
- data/app/assets/stylesheets/tr8n/keyboard_1_49.css +271 -0
- data/app/assets/stylesheets/tr8n/layout.css.scss +23 -0
- data/app/assets/stylesheets/tr8n/tr8n.css.scss +1 -1
- data/app/controllers/tr8n/api/v1/base_controller.rb +6 -0
- data/app/controllers/tr8n/api/v1/language_controller.rb +7 -10
- data/app/controllers/tr8n/api/v1/translation_controller.rb +0 -1
- data/app/javascript/compile.rb +37 -0
- data/app/javascript/compile.sh +1 -0
- data/app/javascript/compressors/google/COPYING +202 -0
- data/app/javascript/compressors/google/README +292 -0
- data/app/javascript/compressors/google/compiler.jar +0 -0
- data/app/javascript/config.yml +66 -0
- data/app/javascript/src/base.js +35 -0
- data/app/javascript/src/effects.js +67 -0
- data/app/javascript/src/ext/inflector.js +309 -0
- data/app/{assets/javascripts/tr8n → javascript/src/ext}/jsDraw2D.js +0 -0
- data/app/{assets/javascripts/tr8n → javascript/src/ext}/keyboard_1_36.js +0 -0
- data/app/{assets/javascripts/tr8n → javascript/src/ext}/keyboard_1_44.js +0 -0
- data/app/javascript/src/ext/keyboard_1_49.js +1796 -0
- data/app/javascript/src/ext/md5.js +209 -0
- data/app/{assets/javascripts/tr8n → javascript/src/ext}/shortcut.js +0 -0
- data/app/javascript/src/init.js +47 -0
- data/app/javascript/src/language.js +38 -0
- data/app/javascript/src/logger.js +203 -0
- data/app/{assets/javascripts/tr8n/tr8n_prototype_effects.js → javascript/src/prototype/effects.js} +5 -5
- data/app/javascript/src/proxy.js +254 -0
- data/app/javascript/src/rules/date_rule.js +37 -0
- data/app/javascript/src/rules/gender_list_rule.js +37 -0
- data/app/javascript/src/rules/gender_rule.js +87 -0
- data/app/javascript/src/rules/language_rule.js +55 -0
- data/app/javascript/src/rules/list_rule.js +37 -0
- data/app/javascript/src/rules/numeric_rule.js +95 -0
- data/app/javascript/src/tml/label.js +60 -0
- data/app/javascript/src/tml/token.js +107 -0
- data/app/javascript/src/tokens/data_token.js +45 -0
- data/app/javascript/src/tokens/decoration_token.js +82 -0
- data/app/javascript/src/tokens/token.js +121 -0
- data/app/javascript/src/tokens/transform_token.js +106 -0
- data/app/javascript/src/translation_key.js +183 -0
- data/app/javascript/src/ui/language_case_manager.js +155 -0
- data/app/javascript/src/ui/language_selector.js +126 -0
- data/app/javascript/src/ui/lightbox.js +72 -0
- data/app/javascript/src/ui/translator.js +257 -0
- data/app/javascript/src/utils.js +286 -0
- data/app/models/tr8n/language_case.rb +27 -16
- data/app/models/tr8n/language_case_rule.rb +24 -7
- data/app/models/tr8n/translation_key.rb +23 -21
- data/app/views/tr8n/common/_scripts.html.erb +8 -10
- data/app/views/tr8n/language_cases/_manager_header.html.erb +3 -3
- data/app/views/tr8n/language_cases/manager.html.erb +2 -2
- data/app/views/tr8n/translations/_original_phrase.html.erb +1 -1
- data/lib/tr8n/extensions/action_view_extension.rb +8 -1
- data/lib/tr8n/keyboard_mapping.rb +101 -0
- data/lib/tr8n/token.rb +1 -2
- data/lib/tr8n/version.rb +1 -1
- data/spec/models/tr8n/gender_rule_spec.rb +6 -6
- data/spec/models/tr8n/language_case_rule_spec.rb +219 -1
- data/spec/models/tr8n/language_case_spec.rb +51 -1
- data/spec/models/tr8n/translation_key_spec.rb +256 -0
- data/tr8n.gemspec +2 -1
- metadata +129 -47
- data/app/assets/javascripts/tr8n/tr8n.js +0 -905
- data/app/assets/javascripts/tr8n/tr8n_client_sdk.js +0 -1472
data/app/{assets/javascripts/tr8n/tr8n_prototype_effects.js → javascript/src/prototype/effects.js}
RENAMED
@@ -1,5 +1,5 @@
|
|
1
1
|
/****************************************************************************
|
2
|
-
Copyright (c) 2010-
|
2
|
+
Copyright (c) 2010-2012 Michael Berkovich, Ian McDaniel, tr8n.net
|
3
3
|
|
4
4
|
Permission is hereby granted, free of charge, to any person obtaining
|
5
5
|
a copy of this software and associated documentation files (the
|
@@ -32,9 +32,9 @@ Tr8n.Effects = {
|
|
32
32
|
show: function(element_id) {
|
33
33
|
$(element_id).show();
|
34
34
|
},
|
35
|
-
|
36
|
-
Effect.BlindUp(element_id, { duration: 0.2 });
|
37
|
-
|
35
|
+
blindUp: function(element_id) {
|
36
|
+
Effect.BlindUp(element_id, { duration: 0.2 });
|
37
|
+
},
|
38
38
|
blindDown: function(element_id) {
|
39
39
|
Effect.BlindDown(element_id, { duration: 0.2 });
|
40
40
|
},
|
@@ -60,6 +60,6 @@ Tr8n.Effects = {
|
|
60
60
|
theElement = theElement.offsetParent;
|
61
61
|
}
|
62
62
|
window.scrollTo(selectedPosX,selectedPosY);
|
63
|
-
}
|
63
|
+
}
|
64
64
|
}
|
65
65
|
|
@@ -0,0 +1,254 @@
|
|
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 = function(options) {
|
25
|
+
var self = this;
|
26
|
+
this.options = options;
|
27
|
+
this.options['url'] = this.options['url'] || '/tr8n/api/v1/language/translate';
|
28
|
+
this.options['scheduler_interval'] = this.options['scheduler_interval'] || 20000;
|
29
|
+
this.logger_enabled = false;
|
30
|
+
this.missing_translations_locked = false;
|
31
|
+
this.inline_translations_enabled = this.options['enable_inline_translations'];
|
32
|
+
this.logger = new Tr8n.Proxy.Logger({
|
33
|
+
'proxy': self,
|
34
|
+
'element_id': options['logger_element_id'] || 'tr8n_debugger'
|
35
|
+
});
|
36
|
+
|
37
|
+
this.language = new Tr8n.Proxy.Language({
|
38
|
+
'proxy': self
|
39
|
+
});
|
40
|
+
|
41
|
+
this.initTranslations();
|
42
|
+
this.runScheduledTasks();
|
43
|
+
}
|
44
|
+
|
45
|
+
Tr8n.Proxy.prototype = {
|
46
|
+
log: function(msg) {
|
47
|
+
this.logger.debug(msg);
|
48
|
+
},
|
49
|
+
logSettings: function() {
|
50
|
+
this.logger.clear();
|
51
|
+
this.logger.logObject(this.options);
|
52
|
+
},
|
53
|
+
logTranslations: function() {
|
54
|
+
this.logger.clear();
|
55
|
+
this.translations = this.translations || {};
|
56
|
+
this.logger.logObject(this.translations);
|
57
|
+
},
|
58
|
+
logMissingTranslations: function() {
|
59
|
+
this.logger.clear();
|
60
|
+
this.missing_translation_keys = this.missing_translation_keys || {};
|
61
|
+
this.logger.logObject(this.missing_translation_keys);
|
62
|
+
},
|
63
|
+
disableLogger: function() {
|
64
|
+
this.logger_enabled = false;
|
65
|
+
},
|
66
|
+
enableLogger: function() {
|
67
|
+
this.logger_enabled = true;
|
68
|
+
},
|
69
|
+
debug: function(msg) {
|
70
|
+
this.logger.debug(msg);
|
71
|
+
},
|
72
|
+
error: function(msg) {
|
73
|
+
this.logger.error(msg);
|
74
|
+
},
|
75
|
+
translate: function(label, description, tokens, options) {
|
76
|
+
if (!label) return "";
|
77
|
+
description = description || "";
|
78
|
+
tokens = tokens || {};
|
79
|
+
options = options || {};
|
80
|
+
return this.language.translate(label, description, tokens, options);
|
81
|
+
},
|
82
|
+
tr: function(label, description, tokens, options) {
|
83
|
+
return this.translate(label, description, tokens, options);
|
84
|
+
},
|
85
|
+
trl: function(label, description, tokens, options) {
|
86
|
+
options = options || {};
|
87
|
+
options['skip_decorations'] = true;
|
88
|
+
return this.translate(label, description, tokens, options);
|
89
|
+
},
|
90
|
+
getTranslations: function() {
|
91
|
+
this.translations = this.translations || {};
|
92
|
+
return this.translations;
|
93
|
+
},
|
94
|
+
getDecorationFor: function(decoration_name) {
|
95
|
+
if (!this.options['default_decorations'])
|
96
|
+
return null;
|
97
|
+
return this.options['default_decorations'][decoration_name];
|
98
|
+
},
|
99
|
+
getLanguageRuleForType: function(rule_type) {
|
100
|
+
// modify this section to add more rules
|
101
|
+
if (rule_type == 'number') return 'Tr8n.Proxy.NumericRule';
|
102
|
+
if (rule_type == 'gender') return 'Tr8n.Proxy.GenderRule';
|
103
|
+
if (rule_type == 'date') return 'Tr8n.Proxy.DateRule';
|
104
|
+
if (rule_type == 'list') return 'Tr8n.Proxy.ListRule';
|
105
|
+
if (rule_type == 'gender_list') return 'Tr8n.Proxy.GenderListRule';
|
106
|
+
return null;
|
107
|
+
},
|
108
|
+
getLanguageRuleForTokenSuffix: function(token_suffix) {
|
109
|
+
if (!this.options['rules']) return null;
|
110
|
+
|
111
|
+
for (rule_type in this.options['rules']) {
|
112
|
+
var suffixes = this.options['rules'][rule_type]['token_suffixes'];
|
113
|
+
if (!suffixes) continue;
|
114
|
+
|
115
|
+
if (Tr8n.Utils.indexOf(suffixes, token_suffix) != -1 )
|
116
|
+
return this.getLanguageRuleForType(rule_type);
|
117
|
+
}
|
118
|
+
return null;
|
119
|
+
},
|
120
|
+
|
121
|
+
registerTranslationKeys: function(translations) {
|
122
|
+
this.log("Found " + translations.length + " registered phrases");
|
123
|
+
for (i = 0; i < translations.length; i++) {
|
124
|
+
var translation_key = translations[i];
|
125
|
+
this.log("Registering " + translation_key['key']);
|
126
|
+
this.translations[translation_key['key']] = translation_key;
|
127
|
+
}
|
128
|
+
},
|
129
|
+
|
130
|
+
initTranslations: function(forced) {
|
131
|
+
if (!forced && this.translations) return;
|
132
|
+
|
133
|
+
this.translations = {};
|
134
|
+
|
135
|
+
// Check for page variable to load translations from, if variable was provided
|
136
|
+
if (this.options['translations_cache_id']) {
|
137
|
+
this.log("Registering page translations from translations cache...");
|
138
|
+
this.updateTranslations(eval(this.options['translations_cache_id']));
|
139
|
+
}
|
140
|
+
|
141
|
+
var self = this;
|
142
|
+
|
143
|
+
// Optionally, fetch translations from the server
|
144
|
+
if (this.options['fetch_translations_on_init']) {
|
145
|
+
this.log("Fetching translations from the server...");
|
146
|
+
Tr8n.Utils.ajax(this.options['url'], {
|
147
|
+
method: 'get',
|
148
|
+
parameters: {'batch': true, 'source': self.options['default_source']},
|
149
|
+
onSuccess: function(response) {
|
150
|
+
self.log("Received response from the server");
|
151
|
+
self.log(response.responseText);
|
152
|
+
self.updateTranslations(eval("[" + response.responseText + "]")[0]['phrases']);
|
153
|
+
}
|
154
|
+
});
|
155
|
+
}
|
156
|
+
},
|
157
|
+
|
158
|
+
updateTranslations: function(new_translations) {
|
159
|
+
this.translations = this.translations || {};
|
160
|
+
this.log("Updating page translations...");
|
161
|
+
this.registerTranslationKeys(new_translations);
|
162
|
+
},
|
163
|
+
|
164
|
+
registerMissingTranslationKey: function(translation_key, token_values, options) {
|
165
|
+
this.missing_translation_keys = this.missing_translation_keys || {};
|
166
|
+
if (!this.missing_translation_keys[translation_key.key]) {
|
167
|
+
this.log('Adding missing translation to the queue: ' + translation_key.key);
|
168
|
+
this.missing_translation_keys[translation_key.key] = {translation_key: translation_key, token_values: token_values, options:options};
|
169
|
+
}
|
170
|
+
},
|
171
|
+
submitMissingTranslationKeys: function() {
|
172
|
+
if (this.missing_translations_locked) {
|
173
|
+
this.log('Missing translations are being processed, postponding registration task.');
|
174
|
+
return;
|
175
|
+
}
|
176
|
+
|
177
|
+
this.missing_translation_keys = this.missing_translation_keys || {};
|
178
|
+
|
179
|
+
var phrases = "[";
|
180
|
+
for (var key in this.missing_translation_keys) {
|
181
|
+
var translation_key = this.missing_translation_keys[key].translation_key;
|
182
|
+
if (translation_key == null) continue;
|
183
|
+
if (phrases!="[") phrases = phrases + ",";
|
184
|
+
phrases = phrases + "{";
|
185
|
+
phrases = phrases + '"label":"' + translation_key.label + '", ';
|
186
|
+
phrases = phrases + '"description":"' + translation_key.description + '"';
|
187
|
+
phrases = phrases + "}";
|
188
|
+
}
|
189
|
+
phrases = phrases + "]";
|
190
|
+
|
191
|
+
if (phrases == '[]') {
|
192
|
+
// this.log('No missing translation keys to submit...');
|
193
|
+
return;
|
194
|
+
}
|
195
|
+
|
196
|
+
var self = this;
|
197
|
+
this.debug('Submitting missing translation keys: ' + phrases);
|
198
|
+
Tr8n.Utils.ajax(this.options['url'], {
|
199
|
+
method: 'put',
|
200
|
+
parameters: {'source': self.options['default_source'], 'phrases': phrases},
|
201
|
+
onSuccess: function(response) {
|
202
|
+
self.log("Received response from the server");
|
203
|
+
self.log(response.responseText);
|
204
|
+
self.updateMissingTranslationKeys(eval("[" + response.responseText + "]")[0]['phrases']);
|
205
|
+
}
|
206
|
+
});
|
207
|
+
},
|
208
|
+
|
209
|
+
updateMissingTranslationKeys: function(translations) {
|
210
|
+
this.missing_translations_locked = true;
|
211
|
+
this.log("Received " + translations.length + " registered phrases...");
|
212
|
+
for (i = 0; i < translations.length; i++) {
|
213
|
+
var translation_key_data = translations[i];
|
214
|
+
|
215
|
+
this.log("Registering new key " + translation_key_data.key);
|
216
|
+
this.translations[translation_key_data.key] = translation_key_data;
|
217
|
+
var missing_key_data = this.missing_translation_keys[translation_key_data.key];
|
218
|
+
var tr8nElement = Tr8n.element(translation_key_data.key);
|
219
|
+
|
220
|
+
if (tr8nElement && missing_key_data.translation_key) {
|
221
|
+
tr8nElement.setAttribute('translation_key_id', translation_key_data['id']);
|
222
|
+
tr8nElement.innerHTML = missing_key_data.translation_key.translate(this.language, missing_key_data.token_values);
|
223
|
+
}
|
224
|
+
|
225
|
+
delete this.missing_translation_keys[missing_key_data.translation_key.key];
|
226
|
+
}
|
227
|
+
this.missing_translations_locked = false;
|
228
|
+
},
|
229
|
+
|
230
|
+
runScheduledTasks: function() {
|
231
|
+
var self = this;
|
232
|
+
|
233
|
+
// this.log("Running scheduled tasks...");
|
234
|
+
this.submitMissingTranslationKeys();
|
235
|
+
|
236
|
+
window.setTimeout(function() {
|
237
|
+
self.runScheduledTasks();
|
238
|
+
}, this.options['scheduler_interval']);
|
239
|
+
},
|
240
|
+
|
241
|
+
initTml: function() {
|
242
|
+
var tree_walker = document.createTreeWalker(document.body, NodeFilter.SHOW_ALL, function(node) {
|
243
|
+
if (node.nodeName == 'TML:LABEL') {
|
244
|
+
return NodeFilter.FILTER_ACCEPT;
|
245
|
+
} else {
|
246
|
+
return NodeFilter.FILTER_SKIP;
|
247
|
+
}
|
248
|
+
}, false);
|
249
|
+
|
250
|
+
while (tree_walker.nextNode()) {
|
251
|
+
new Tr8n.Tml.Label(tree_walker.currentNode, this).translate();
|
252
|
+
}
|
253
|
+
}
|
254
|
+
}
|
@@ -0,0 +1,37 @@
|
|
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.DateRule = function(definition, options) {
|
25
|
+
this.definition = definition;
|
26
|
+
this.options = options;
|
27
|
+
}
|
28
|
+
|
29
|
+
Tr8n.Proxy.DateRule.prototype = new Tr8n.Proxy.LanguageRule();
|
30
|
+
|
31
|
+
Tr8n.Proxy.DateRule.transform = function(object, values) {
|
32
|
+
return "";
|
33
|
+
}
|
34
|
+
|
35
|
+
Tr8n.Proxy.DateRule.prototype.evaluate = function(token, token_values) {
|
36
|
+
return true;
|
37
|
+
}
|
@@ -0,0 +1,37 @@
|
|
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.GenderListRule = function(definition, options) {
|
25
|
+
this.definition = definition;
|
26
|
+
this.options = options;
|
27
|
+
}
|
28
|
+
|
29
|
+
Tr8n.Proxy.GenderListRule.prototype = new Tr8n.Proxy.LanguageRule();
|
30
|
+
|
31
|
+
Tr8n.Proxy.GenderListRule.transform = function(object, values) {
|
32
|
+
return "";
|
33
|
+
}
|
34
|
+
|
35
|
+
Tr8n.Proxy.GenderListRule.prototype.evaluate = function(token, token_values) {
|
36
|
+
return true;
|
37
|
+
}
|
@@ -0,0 +1,87 @@
|
|
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.GenderRule = function(definition, options) {
|
25
|
+
this.definition = definition;
|
26
|
+
this.options = options;
|
27
|
+
}
|
28
|
+
|
29
|
+
Tr8n.Proxy.GenderRule.prototype = new Tr8n.Proxy.LanguageRule();
|
30
|
+
|
31
|
+
// FORM: [male, female, unknown]
|
32
|
+
// {user | registered on}
|
33
|
+
// {user | he, she}
|
34
|
+
// {user | he, she, he/she}
|
35
|
+
Tr8n.Proxy.GenderRule.transform = function(object, values) {
|
36
|
+
if (values.length == 1) return values[0];
|
37
|
+
|
38
|
+
if (typeof object == 'string') {
|
39
|
+
if (object == 'male') return values[0];
|
40
|
+
if (object == 'female') return values[1];
|
41
|
+
} else if (typeof object == 'object') {
|
42
|
+
if (object['gender'] == 'male') return values[0];
|
43
|
+
if (object['gender'] == 'female') return values[1];
|
44
|
+
}
|
45
|
+
|
46
|
+
if (values.length == 3) return values[2];
|
47
|
+
return values[0] + "/" + values[1];
|
48
|
+
}
|
49
|
+
|
50
|
+
Tr8n.Proxy.GenderRule.prototype.evaluate = function(token_name, token_values) {
|
51
|
+
|
52
|
+
var object = this.getTokenValue(token_name, token_values);
|
53
|
+
if (!object) return false;
|
54
|
+
|
55
|
+
var gender = "";
|
56
|
+
|
57
|
+
if (typeof object != 'object') {
|
58
|
+
this.getLogger().error("Invalid token value for gender based token: " + token_name + ". Token value must be an object.");
|
59
|
+
return false;
|
60
|
+
}
|
61
|
+
|
62
|
+
if (!object['subject']) {
|
63
|
+
this.getLogger().error("Invalid token subject for gender based token: " + token_name + ". Token value must contain a subject. Subject can be a string or an object with a gender.");
|
64
|
+
return false;
|
65
|
+
}
|
66
|
+
|
67
|
+
if (typeof object['subject'] == 'string') {
|
68
|
+
gender = object['subject'];
|
69
|
+
} else if (typeof object['subject'] == 'object') {
|
70
|
+
gender = object['subject']['gender'];
|
71
|
+
if (!gender) {
|
72
|
+
this.getLogger().error("Cannot determine gender for token subject: " + token_name);
|
73
|
+
return false;
|
74
|
+
}
|
75
|
+
} else {
|
76
|
+
this.getLogger().error("Invalid token subject for gender based token: " + token_name + ". Subject does not have a gender.");
|
77
|
+
return false;
|
78
|
+
}
|
79
|
+
|
80
|
+
if (this.definition['operator'] == "is") {
|
81
|
+
return (gender == this.definition['value']);
|
82
|
+
} else if (this.definition['operator'] == "is_not") {
|
83
|
+
return (gender != this.definition['value']);
|
84
|
+
}
|
85
|
+
|
86
|
+
return false;
|
87
|
+
}
|
@@ -0,0 +1,55 @@
|
|
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.LanguageRule = function() {}
|
25
|
+
|
26
|
+
Tr8n.Proxy.LanguageRule.prototype = {
|
27
|
+
getProxy: function() {
|
28
|
+
return this.options['proxy'];
|
29
|
+
},
|
30
|
+
getLogger: function() {
|
31
|
+
return this.getProxy().logger;
|
32
|
+
},
|
33
|
+
getTokenValue: function(token_name, token_values) {
|
34
|
+
var object = token_values[token_name];
|
35
|
+
if (object == null) {
|
36
|
+
this.getLogger().error("Invalid token value for token: " + token_name);
|
37
|
+
}
|
38
|
+
|
39
|
+
return object;
|
40
|
+
},
|
41
|
+
getDefinitionDescription: function() {
|
42
|
+
var result = [];
|
43
|
+
for (var key in this.definition)
|
44
|
+
result.push(key + ": '" + this.definition[key] + "'");
|
45
|
+
return "{" + result.join(", ") + "}";
|
46
|
+
},
|
47
|
+
sanitizeArrayValue: function(value) {
|
48
|
+
var results = [];
|
49
|
+
var arr = value.split(',');
|
50
|
+
for (var index = 0; index < arr.length; index++) {
|
51
|
+
results.push(Tr8n.Utils.trim(arr[index]));
|
52
|
+
}
|
53
|
+
return results;
|
54
|
+
}
|
55
|
+
}
|