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.
Files changed (42) hide show
  1. data/Gemfile.lock +1 -1
  2. data/lib/tr8n/version.rb +1 -1
  3. data/tr8n.gemspec +2 -2
  4. metadata +41 -117
  5. data/app/javascript/compile.rb +0 -37
  6. data/app/javascript/compile.sh +0 -1
  7. data/app/javascript/compressors/google/COPYING +0 -202
  8. data/app/javascript/compressors/google/README +0 -292
  9. data/app/javascript/compressors/google/compiler.jar +0 -0
  10. data/app/javascript/config.yml +0 -66
  11. data/app/javascript/src/base.js +0 -35
  12. data/app/javascript/src/effects.js +0 -67
  13. data/app/javascript/src/ext/inflector.js +0 -309
  14. data/app/javascript/src/ext/jsDraw2D.js +0 -24
  15. data/app/javascript/src/ext/keyboard_1_36.js +0 -1214
  16. data/app/javascript/src/ext/keyboard_1_44.js +0 -1735
  17. data/app/javascript/src/ext/keyboard_1_49.js +0 -1796
  18. data/app/javascript/src/ext/md5.js +0 -209
  19. data/app/javascript/src/ext/shortcut.js +0 -223
  20. data/app/javascript/src/init.js +0 -47
  21. data/app/javascript/src/language.js +0 -38
  22. data/app/javascript/src/logger.js +0 -203
  23. data/app/javascript/src/prototype/effects.js +0 -65
  24. data/app/javascript/src/proxy.js +0 -254
  25. data/app/javascript/src/rules/date_rule.js +0 -37
  26. data/app/javascript/src/rules/gender_list_rule.js +0 -37
  27. data/app/javascript/src/rules/gender_rule.js +0 -87
  28. data/app/javascript/src/rules/language_rule.js +0 -55
  29. data/app/javascript/src/rules/list_rule.js +0 -37
  30. data/app/javascript/src/rules/numeric_rule.js +0 -95
  31. data/app/javascript/src/tml/label.js +0 -60
  32. data/app/javascript/src/tml/token.js +0 -107
  33. data/app/javascript/src/tokens/data_token.js +0 -45
  34. data/app/javascript/src/tokens/decoration_token.js +0 -82
  35. data/app/javascript/src/tokens/token.js +0 -121
  36. data/app/javascript/src/tokens/transform_token.js +0 -106
  37. data/app/javascript/src/translation_key.js +0 -183
  38. data/app/javascript/src/ui/language_case_manager.js +0 -155
  39. data/app/javascript/src/ui/language_selector.js +0 -126
  40. data/app/javascript/src/ui/lightbox.js +0 -72
  41. data/app/javascript/src/ui/translator.js +0 -257
  42. data/app/javascript/src/utils.js +0 -286
@@ -1,38 +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.Language = function(options) {
25
- this.options = options;
26
- }
27
-
28
- Tr8n.Proxy.Language.prototype = {
29
- getProxy: function() {
30
- return this.options['proxy'];
31
- },
32
- getLogger: function() {
33
- return this.getProxy().logger;
34
- },
35
- translate: function(label, description, tokens, options) {
36
- return (new Tr8n.Proxy.TranslationKey(label, description, {'proxy': this.getProxy()}).translate(this, tokens, options));
37
- }
38
- }
@@ -1,203 +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.Logger = function(options) {
25
- this.options = options;
26
- this.object_keys = [];
27
- }
28
-
29
- Tr8n.Proxy.Logger.prototype = {
30
- clear: function() {
31
- if (!this.options['proxy'].logger_enabled) return;
32
- if (!this.options['element_id']) return;
33
- if (!Tr8n.element(this.options['element_id'])) return;
34
- Tr8n.element(this.options['element_id']).innerHTML = "";
35
- },
36
- append: function(msg) {
37
- if (!this.options['proxy'].logger_enabled) return;
38
- if (!this.options['element_id']) return;
39
- if (!Tr8n.element(this.options['element_id'])) return;
40
-
41
- var str = msg + "<br>" + Tr8n.element(this.options['element_id']).innerHTML;
42
- Tr8n.element(this.options['element_id']).innerHTML = str;
43
- },
44
- log: function(msg) {
45
- if (!this.options['proxy'].logger_enabled) return;
46
- var now = new Date();
47
- var str = "<span style='color:#ccc;'>" + (now.toLocaleDateString() + " " + now.toLocaleTimeString()) + "</span>: " + msg;
48
- this.append(str);
49
- },
50
- debug: function(msg) {
51
- if (!this.options['proxy'].logger_enabled) return;
52
- if (window.console && console.log) {
53
- console.log(msg);
54
- }
55
- this.log("<span style='color:grey'>" + msg + "</span>");
56
- },
57
- error: function(msg) {
58
- if (!this.options['proxy'].logger_enabled) return;
59
- if (window.console && console.error) {
60
- console.error(msg);
61
- }
62
- this.log("<span style='color:red'>" + msg + "</span>");
63
- },
64
- S4: function() {
65
- return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
66
- },
67
- guid: function() {
68
- return (this.S4()+this.S4()+"-"+this.S4()+"-"+this.S4()+"-"+this.S4()+"-"+this.S4()+this.S4()+this.S4());
69
- },
70
- escapeHTML: function(str) {
71
- return( str.replace(/&/g,'&amp;').replace(/>/g,'&gt;').replace(/</g,'&lt;').replace(/"/g,'&quot;'));
72
- },
73
- showObject: function (obj_key, flag) {
74
- if (flag) {
75
- Tr8n.Effects.hide("no_object_" + obj_key);
76
- Tr8n.Effects.show("object_" + obj_key);
77
- Tr8n.element("expander_" + obj_key).innerHTML = "<img src='/assets/tr8n/minus_node.png'>";
78
- } else {
79
- Tr8n.Effects.hide("object_" + obj_key);
80
- Tr8n.Effects.show("no_object_" + obj_key);
81
- Tr8n.element("expander_" + obj_key).innerHTML = "<img src='/assets/tr8n/plus_node.png'>";
82
- }
83
- },
84
- toggleNode: function(obj_key) {
85
- this.showObject(obj_key, (Tr8n.element("object_" + obj_key).style.display == 'none'));
86
- },
87
- expandAllNodes: function() {
88
- for (var i=0; i<this.object_keys.length; i++) {
89
- this.showObject(this.object_keys[i], true);
90
- }
91
- },
92
- collapseAllNodes: function() {
93
- for (var i=0; i<this.object_keys.length; i++) {
94
- this.showObject(this.object_keys[i], false);
95
- }
96
- },
97
- logObject: function(data) {
98
- this.object_keys = [];
99
- html = []
100
- html.push("<div style='float:right;padding-right:10px;'>");
101
- html.push("<span style='padding:2px;' onClick=\"tr8nProxy.logger.expandAllNodes()\"><img src='/assets/tr8n/plus_node.png'></span>");
102
- html.push("<span style='padding:2px;' onClick=\"tr8nProxy.logger.collapseAllNodes()\"><img src='/assets/tr8n/minus_node.png'></span>");
103
- html.push("</div>");
104
-
105
- var results = data;
106
- if (typeof results == 'string') {
107
- try {
108
- results = eval("[" + results + "]")[0];
109
- }
110
- catch (err) {
111
- this.push(results);
112
- return;
113
- }
114
- }
115
- if (typeof results == 'object') {
116
- html.push(this.formatObject(results, 1));
117
- } else {
118
- html.push(results);
119
- }
120
- this.append(html.join(""));
121
- },
122
- formatObject: function(obj, level) {
123
- if (obj == null) return "{<br>}";
124
-
125
- var html = [];
126
- var obj_key = this.guid();
127
- html.push("<span class='tr8n_logger_expander' id='expander_" + obj_key + "' onClick=\"tr8nProxy.logger.toggleNode('" + obj_key + "')\"><img src='/assets/tr8n/minus_node.png'></span> <span style='display:none' id='no_object_" + obj_key + "'>{...}</span> <span id='object_" + obj_key + "'>{");
128
- this.object_keys.push(obj_key);
129
-
130
- var keys = Object.keys(obj).sort();
131
-
132
- for (var i=0; i<keys.length; i++) {
133
- key = keys[i];
134
- if (this.isObject(obj[key])) {
135
- if (this.isArray(obj[key])) {
136
- html.push(this.createSpacer(level) + "<span class='tr8n_logger_obj_key'>" + key + ":</span>" + this.formatArray(obj[key], level + 1) + ",");
137
- } else {
138
- html.push(this.createSpacer(level) + "<span class='tr8n_logger_obj_key'>" + key + ":</span>" + this.formatObject(obj[key], level + 1) + ",");
139
- }
140
- } else {
141
- html.push(this.createSpacer(level) + this.formatProperty(key, obj[key]) + ",");
142
- }
143
- }
144
- html.push(this.createSpacer(level-1) + "}</span>");
145
- return html.join("<br>");
146
- },
147
- formatArray: function(arr, level) {
148
- if (arr == null) return "[<br>]";
149
-
150
- var html = [];
151
- var obj_key = this.guid();
152
- html.push("<span class='tr8n_logger_expander' id='expander_" + obj_key + "' onClick=\"tr8nProxy.logger.toggleNode('" + obj_key + "')\"><img src='/assets/tr8n/minus_node.png'></span> <span style='display:none' id='no_object_" + obj_key + "'>[...]</span> <span id='object_" + obj_key + "'>[");
153
- this.object_keys.push(obj_key);
154
-
155
- for (var i=0; i<arr.length; i++) {
156
- if (this.isObject(arr[i])) {
157
- if (this.isArray(arr[i])) {
158
- html.push(this.createSpacer(level) + this.formatArray(arr[i], level + 1) + ",");
159
- } else {
160
- html.push(this.createSpacer(level) + this.formatObject(arr[i], level + 1) + ",");
161
- }
162
- } else {
163
- html.push(this.createSpacer(level) + this.formatProperty(null, arr[i]) + ",");
164
- }
165
- }
166
- html.push(this.createSpacer(level-1) + "]</span>");
167
- return html.join("<br>");
168
- },
169
- formatProperty: function(key, value) {
170
- if (value == null) return "<span class='tr8n_logger_obj_key'>" + key + ":</span><span class='obj_value_null'>null</span>";
171
-
172
- var cls = "tr8n_logger_obj_value_" + (typeof value);
173
- var value_span = "";
174
-
175
- if (this.isString(value))
176
- value_span = "<span class='" + cls + "'>\"" + this.escapeHTML(value) + "\"</span>";
177
- else
178
- value_span = "<span class='" + cls + "'>" + value + "</span>";
179
-
180
- if (key == null)
181
- return value_span;
182
-
183
- return "<span class='tr8n_logger_obj_key'>" + key + ":</span>" + value_span;
184
- },
185
- createSpacer: function(level) {
186
- return "<img src='/assets/tr8n/pixel.gif' style='height:1px;width:" + (level * 20) + "px;'>";
187
- },
188
- isArray: function(obj) {
189
- if (obj == null) return false;
190
- return !(obj.constructor.toString().indexOf("Array") == -1);
191
- },
192
- isObject: function(obj) {
193
- if (obj == null) return false;
194
- return (typeof obj == 'object');
195
- },
196
- isString: function(obj) {
197
- return (typeof obj == 'string');
198
- },
199
- isURL: function(str) {
200
- str = "" + str;
201
- return (str.indexOf("http://") != -1) || (str.indexOf("https://") != -1);
202
- }
203
- }
@@ -1,65 +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
- /****************************************************************************
25
- **** Tr8n Prototype Effects Functions
26
- ****************************************************************************/
27
-
28
- Tr8n.Effects = {
29
- hide: function(element_id) {
30
- $(element_id).hide();
31
- },
32
- show: function(element_id) {
33
- $(element_id).show();
34
- },
35
- blindUp: function(element_id) {
36
- Effect.BlindUp(element_id, { duration: 0.2 });
37
- },
38
- blindDown: function(element_id) {
39
- Effect.BlindDown(element_id, { duration: 0.2 });
40
- },
41
- appear: function(element_id) {
42
- Effect.Appear(element_id, { duration: 0.2 });
43
- },
44
- fade: function(element_id) {
45
- Effect.Fade(element_id, { duration: 0.2 });
46
- },
47
- submit: function(element_id) {
48
- $(element_id).submit();
49
- },
50
- focus: function(element_id) {
51
- $(element_id).focus();
52
- },
53
- scrollTo: function(element_id) {
54
- var theElement = $(element_id);
55
- var selectedPosX = 0;
56
- var selectedPosY = 0;
57
- while(theElement != null){
58
- selectedPosX += theElement.offsetLeft;
59
- selectedPosY += theElement.offsetTop;
60
- theElement = theElement.offsetParent;
61
- }
62
- window.scrollTo(selectedPosX,selectedPosY);
63
- }
64
- }
65
-
@@ -1,254 +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 = 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
- }