tr8n 3.2.2 → 3.2.3

Sign up to get free protection for your applications and to get access to all the features.
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,155 +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.LanguageCaseManager = function(options) {
25
- var self = this;
26
- this.options = options;
27
- this.case_key = null;
28
-
29
- this.container = document.createElement('div');
30
- this.container.className = 'tr8n_language_case_manager';
31
- this.container.id = 'tr8n_language_case_manager';
32
- this.container.style.display = "none";
33
-
34
- document.body.appendChild(this.container)
35
-
36
- var event_type = Tr8n.Utils.isOpera() ? 'click' : 'contextmenu';
37
-
38
- Tr8n.Utils.addEvent(document, event_type, function(e) {
39
- if (Tr8n.Utils.isOpera() && !e.ctrlKey) return;
40
-
41
- var case_node = Tr8n.Utils.findElement(e, ".tr8n_language_case");
42
- var link_node = Tr8n.Utils.findElement(e, "a");
43
-
44
- if (case_node == null) return;
45
-
46
- if (link_node) {
47
- var temp_href = link_node.href;
48
- link_node.href='javascript:void(0);';
49
- setTimeout(function() {link_node.href = temp_href;}, 500);
50
- }
51
-
52
- if (e.stop) e.stop();
53
- if (e.preventDefault) e.preventDefault();
54
- if (e.stopPropagation) e.stopPropagation();
55
-
56
- self.show(case_node);
57
- });
58
- }
59
-
60
- Tr8n.LanguageCaseManager.prototype = {
61
- hide: function() {
62
- this.container.style.display = "none";
63
- Tr8n.Utils.showFlash();
64
- },
65
-
66
- show: function(case_node) {
67
- var self = this;
68
- if (tr8nLanguageSelector) tr8nLanguageSelector.hide();
69
- if (tr8nLightbox) tr8nLightbox.hide();
70
- if (tr8nTranslator) tr8nTranslator.hide();
71
- Tr8n.Utils.hideFlash();
72
-
73
- var html = "";
74
- var splash_screen = Tr8n.element('tr8n_splash_screen');
75
-
76
- if (splash_screen) {
77
- html += splash_screen.innerHTML;
78
- } else {
79
- html += "<div style='font-size:18px;text-align:center; margin:5px; padding:10px; background-color:black;'>";
80
- html += " <img src='/assets/tr8n/tr8n_logo.jpg' style='width:280px; vertical-align:middle;'>";
81
- html += " <img src='/assets/tr8n/loading3.gif' style='width:200px; height:20px; vertical-align:middle;'>";
82
- html += "</div>"
83
- }
84
- this.container.innerHTML = html;
85
- this.container.style.display = "block";
86
-
87
- var stem = {v:"top", h:"left",width:10, height:12};
88
- var stem_type = "top_left";
89
- var target_dimensions = {width:case_node.offsetWidth, height:case_node.offsetHeight};
90
- var target_position = Tr8n.Utils.cumulativeOffset(case_node);
91
- var container_position = {
92
- left: (target_position[0] + 'px'),
93
- top : (target_position[1] + target_dimensions.height + stem.height + 'px')
94
- }
95
-
96
- var stem_offset = target_dimensions.width/2;
97
- var scroll_buffer = 100;
98
- var scroll_height = target_position[1] - scroll_buffer;
99
-
100
- if (window.innerWidth < target_position[0] + target_dimensions.width + window.innerWidth/2) {
101
- container_position.left = target_position[0] + target_dimensions.width - this.container.offsetWidth + "px";
102
- stem_offset = target_dimensions.width/2;
103
- stem.h = "right";
104
- }
105
-
106
- window.scrollTo(target_position[0], scroll_height);
107
- this.container.style.left = container_position.left;
108
- this.container.style.top = container_position.top;
109
- this.case_id = case_node.getAttribute('case_id');
110
- this.rule_id = case_node.getAttribute('rule_id');
111
- this.case_key = case_node.getAttribute('case_key');
112
-
113
- window.setTimeout(function() {
114
- Tr8n.Utils.update('tr8n_language_case_manager', '/tr8n/language_cases/manager', {
115
- evalScripts: true,
116
- parameters: {
117
- case_id: self.case_id,
118
- rule_id: self.rule_id,
119
- case_key: self.case_key,
120
- stem_type: stem.v + "_" + stem.h,
121
- stem_offset: stem_offset
122
- }
123
- });
124
- }, 500);
125
- },
126
-
127
- switchToCaseMapMode: function() {
128
- Tr8n.Effects.hide('tr8n_language_case_container');
129
- Tr8n.Effects.show('tr8n_language_case_exception_container');
130
- },
131
-
132
- switchCaseMapMode: function(mode) {
133
- var self = this;
134
- Tr8n.Utils.update('tr8n_language_cases_form', '/tr8n/language_cases/switch_manager_mode', {
135
- evalScripts: true,
136
- parameters: {mode: mode, case_key: self.case_key}
137
- });
138
- },
139
-
140
- reportCaseMap: function(map_id) {
141
- var msg = "Reporting these values will remove them from the system and the translator will be put on a watch list. \n\nAre you sure you want to report these values?";
142
- if (!confirm(msg)) return;
143
-
144
- Tr8n.element("tr8n_language_case_form").action = "/tr8n/language_cases/report_value_map";
145
- Tr8n.Effects.hide('tr8n_language_case_exception_container');
146
- Tr8n.Effects.show('tr8n_language_case_report_spinner');
147
- Tr8n.Effects.submit('tr8n_language_case_form');
148
- },
149
-
150
- submitCaseMap: function() {
151
- Tr8n.Effects.hide('tr8n_language_case_exception_container');
152
- Tr8n.Effects.show('tr8n_language_case_submit_spinner');
153
- Tr8n.Effects.submit('tr8n_language_case_form');
154
- }
155
- }
@@ -1,126 +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.LanguageSelector = function(options) {
25
- this.options = options || {};
26
- this.keyboardMode = false;
27
- this.loaded = false;
28
-
29
- this.container = document.createElement('div');
30
- this.container.className = 'tr8n_language_selector';
31
- this.container.id = 'tr8n_language_selector';
32
- this.container.style.display = "none";
33
-
34
- document.body.appendChild(this.container);
35
- }
36
-
37
- Tr8n.LanguageSelector.prototype = {
38
-
39
- toggle: function() {
40
- if (this.container.style.display == "none") {
41
- this.show();
42
- } else {
43
- this.hide();
44
- }
45
- },
46
-
47
- hide: function() {
48
- this.container.style.display = "none";
49
- Tr8n.Utils.showFlash();
50
- },
51
-
52
- show: function() {
53
- var self = this;
54
- if (tr8nTranslator) tr8nTranslator.hide();
55
- if (tr8nLightbox) tr8nLightbox.hide();
56
- if (tr8nLanguageCaseManager) tr8nLanguageCaseManager.hide();
57
- Tr8n.Utils.hideFlash();
58
-
59
- var splash_screen = Tr8n.element('tr8n_splash_screen');
60
-
61
- if (!this.loaded) {
62
- var html = "";
63
- if (splash_screen) {
64
- html += splash_screen.innerHTML;
65
- } else {
66
- html += "<div style='font-size:18px;text-align:center; margin:5px; padding:10px; background-color:black;'>";
67
- html += " <img src='/assets/tr8n/tr8n_logo.jpg' style='width:280px; vertical-align:middle;'>";
68
- html += " <img src='/assets/tr8n/loading3.gif' style='width:200px; height:20px; vertical-align:middle;'>";
69
- html += "</div>";
70
- }
71
- this.container.innerHTML = html;
72
- }
73
- this.container.style.display = "block";
74
-
75
- var trigger = Tr8n.element('tr8n_language_selector_trigger');
76
- var trigger_position = Tr8n.Utils.cumulativeOffset(trigger);
77
- var container_position = {
78
- left: trigger_position[0] + trigger.offsetWidth - this.container.offsetWidth + 'px',
79
- top: trigger_position[1] + trigger.offsetHeight + 4 + 'px'
80
- }
81
-
82
- // if (trigger_position[0] < window.innerWidth/2 ) {
83
- // this.container.offsetLeft = trigger_position[0] + 'px';
84
- // }
85
-
86
- this.container.style.left = container_position.left;
87
- this.container.style.top = container_position.top;
88
-
89
- if (!this.loaded) {
90
- window.setTimeout(function() {
91
- Tr8n.Utils.update('tr8n_language_selector', '/tr8n/language/select', {
92
- evalScripts: true
93
- })
94
- }, 100);
95
- }
96
-
97
- this.loaded = true;
98
- },
99
-
100
- removeLanguage: function(language_id) {
101
- Tr8n.Utils.update('tr8n_language_lists', '/tr8n/language/lists', {
102
- parameters: {language_action: "remove", language_id: language_id},
103
- method: 'post'
104
- });
105
- },
106
-
107
- enableInlineTranslations: function() {
108
- window.location = "/tr8n/language/switch?language_action=enable_inline_mode&source_url=" + location;
109
- },
110
-
111
- disableInlineTranslations: function() {
112
- window.location = "/tr8n/language/switch?language_action=disable_inline_mode&source_url=" + location;
113
- },
114
-
115
- showDashboard: function() {
116
- window.location = "/tr8n/dashboard";
117
- },
118
-
119
- manageLanguage: function() {
120
- window.location = "/tr8n/language";
121
- },
122
-
123
- toggleInlineTranslations: function() {
124
- window.location = "/tr8n/language/switch?language_action=toggle_inline_mode&source_url=" + location;
125
- }
126
- }
@@ -1,72 +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.Lightbox = function() {
25
- this.container = document.createElement('div');
26
- this.container.className = 'tr8n_lightbox';
27
- this.container.id = 'tr8n_lightbox';
28
- this.container.style.display = "none";
29
-
30
- this.overlay = document.createElement('div');
31
- this.overlay.className = 'tr8n_lightbox_overlay';
32
- this.overlay.id = 'tr8n_lightbox_overlay';
33
- this.overlay.style.display = "none";
34
-
35
- document.body.appendChild(this.container);
36
- document.body.appendChild(this.overlay);
37
- }
38
-
39
- Tr8n.Lightbox.prototype = {
40
-
41
- hide: function() {
42
- this.container.style.display = "none";
43
- this.overlay.style.display = "none";
44
- Tr8n.Utils.showFlash();
45
- },
46
-
47
- show: function(url, opts) {
48
- var self = this;
49
- opts = opts || {};
50
- if(tr8nTranslator) tr8nTranslator.hide();
51
- if(tr8nLanguageSelector) tr8nLanguageSelector.hide();
52
- if(tr8nLanguageCaseManager) tr8nLanguageCaseManager.hide();
53
- Tr8n.Utils.hideFlash();
54
-
55
- this.container.innerHTML = "<div class='inner'><div class='bd'><img src='/assets/tr8n/spinner.gif' style='vertical-align:middle'> Loading...</div></div>";
56
-
57
- this.overlay.style.display = "block";
58
-
59
- opts["width"] = opts["width"] || 700;
60
- opts["height"] = opts["height"] || 520;
61
-
62
- this.container.style.width = opts["width"] + 'px';
63
- this.container.style.height = opts["height"] + 'px';
64
- this.container.style.marginLeft = -opts["width"]/2 + 'px';
65
- this.container.style.marginTop = -opts["height"]/2 + 'px';
66
- this.container.style.display = "block";
67
-
68
- Tr8n.Utils.update('tr8n_lightbox', url, {
69
- evalScripts: true
70
- });
71
- }
72
- }
@@ -1,257 +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.Translator = function(options) {
25
- var self = this;
26
- this.options = options;
27
- this.translation_key_id = null;
28
- this.suggestion_tokens = null;
29
-
30
- this.container = document.createElement('div');
31
- this.container.className = 'tr8n_translator';
32
- this.container.id = 'tr8n_translator';
33
- this.container.style.display = "none";
34
-
35
- document.body.appendChild(this.container);
36
-
37
-
38
- var event_type = Tr8n.Utils.isOpera() ? 'click' : 'contextmenu';
39
-
40
- Tr8n.Utils.addEvent(document, event_type, function(e) {
41
- if (Tr8n.Utils.isOpera() && !e.ctrlKey) return;
42
-
43
- var translatable_node = Tr8n.Utils.findElement(e, ".tr8n_translatable");
44
- var link_node = Tr8n.Utils.findElement(e, "a");
45
-
46
- if (translatable_node == null) return;
47
-
48
- if (link_node) {
49
- var temp_href = link_node.href;
50
- link_node.href='javascript:void(0);';
51
- setTimeout(function() {link_node.href = temp_href;}, 500);
52
- }
53
-
54
- if (e.stop) e.stop();
55
- if (e.preventDefault) e.preventDefault();
56
- if (e.stopPropagation) e.stopPropagation();
57
-
58
- self.show(translatable_node);
59
- return false;
60
- });
61
- }
62
-
63
- Tr8n.Translator.prototype = {
64
- hide: function() {
65
- this.container.style.display = "none";
66
- Tr8n.Utils.showFlash();
67
- },
68
-
69
- show: function(translatable_node) {
70
- var self = this;
71
- if (tr8nLanguageSelector) tr8nLanguageSelector.hide();
72
- if (tr8nLightbox) tr8nLightbox.hide();
73
- if (tr8nLanguageCaseManager) tr8nLanguageCaseManager.hide();
74
- Tr8n.Utils.hideFlash();
75
-
76
- var html = "";
77
- var splash_screen = Tr8n.element('tr8n_splash_screen');
78
-
79
- if (splash_screen) {
80
- html += splash_screen.innerHTML;
81
- } else {
82
- html += "<div style='font-size:18px;text-align:center; margin:5px; padding:10px; background-color:black;'>";
83
- html += " <img src='/assets/tr8n/tr8n_logo.jpg' style='width:280px; vertical-align:middle;'>";
84
- html += " <img src='/assets/tr8n/loading3.gif' style='width:200px; height:20px; vertical-align:middle;'>";
85
- html += "</div>"
86
- }
87
- this.container.innerHTML = html;
88
- this.container.style.display = "block";
89
-
90
- var stem = {v:"top", h:"left",width:10, height:12};
91
- var stem_type = "top_left";
92
- var target_dimensions = {width:translatable_node.offsetWidth, height:translatable_node.offsetHeight};
93
- var target_position = Tr8n.Utils.cumulativeOffset(translatable_node);
94
- var container_position = {
95
- left: (target_position[0] + 'px'),
96
- top : (target_position[1] + target_dimensions.height + stem.height + 'px')
97
- }
98
-
99
- var stem_offset = target_dimensions.width/2;
100
- var scroll_buffer = 100;
101
- var scroll_height = target_position[1] - scroll_buffer;
102
-
103
- if (window.innerWidth < target_position[0] + target_dimensions.width + window.innerWidth/2) {
104
- container_position.left = target_position[0] + target_dimensions.width - this.container.offsetWidth + "px";
105
- stem_offset = target_dimensions.width/2;
106
- stem.h = "right";
107
- }
108
-
109
- window.scrollTo(target_position[0], scroll_height);
110
- this.container.style.left = container_position.left;
111
- this.container.style.top = container_position.top;
112
- this.translation_key_id = translatable_node.getAttribute('translation_key_id');
113
-
114
- window.setTimeout(function() {
115
- Tr8n.Utils.update('tr8n_translator', '/tr8n/language/translator', {
116
- evalScripts: true,
117
- parameters: {
118
- translation_key_id: self.translation_key_id,
119
- stem_type: stem.v + "_" + stem.h,
120
- stem_offset: stem_offset
121
- }
122
- });
123
- }, 500);
124
- },
125
-
126
- reportTranslation: function(key, translation_id) {
127
- var msg = "Reporting this translation will remove it from this list and the translator will be put on a watch list. \n\nAre you sure you want to report this translation?";
128
- if (!confirm(msg)) return;
129
- this.voteOnTranslation(key, translation_id, -1000);
130
- },
131
-
132
- voteOnTranslation: function(key, translation_id, vote) {
133
- Tr8n.Effects.hide('tr8n_votes_for_' + translation_id);
134
- Tr8n.Effects.show('tr8n_spinner_for_' + translation_id);
135
-
136
- // the long version updates and reorders translations - used in translator and phrase list
137
- // the short version only updates the total results - used everywhere else
138
- if (Tr8n.element('tr8n_translator_votes_for_' + key)) {
139
- Tr8n.Utils.update('tr8n_translator_votes_for_' + key, '/tr8n/translations/vote', {
140
- parameters: {
141
- translation_id: translation_id,
142
- vote: vote
143
- },
144
- method: 'post'
145
- });
146
- } else {
147
- Tr8n.Utils.update('tr8n_votes_for_' + translation_id, '/tr8n/translations/vote', {
148
- parameters: {
149
- translation_id: translation_id,
150
- vote: vote,
151
- short_version: true
152
- },
153
- method: 'post',
154
- onComplete: function() {
155
- Tr8n.Effects.hide('tr8n_spinner_for_' + translation_id);
156
- Tr8n.Effects.show('tr8n_votes_for_' + translation_id);
157
- }
158
- });
159
- }
160
- },
161
-
162
- insertDecorationToken: function (token, txtarea_id) {
163
- txtarea_id = txtarea_id || 'tr8n_translator_translation_label';
164
- Tr8n.Utils.wrapText(txtarea_id, "[" + token + ": ", "]");
165
- },
166
-
167
- insertToken: function (token, txtarea_id) {
168
- txtarea_id = txtarea_id || 'tr8n_translator_translation_label';
169
- Tr8n.Utils.insertAtCaret(txtarea_id, "{" + token + "}");
170
- },
171
-
172
- switchTranslatorMode: function(translation_key_id, mode, source_url) {
173
- Tr8n.Utils.update('tr8n_translator_container', '/tr8n/language/translator', {
174
- parameters: {translation_key_id: translation_key_id, mode: mode, source_url: source_url},
175
- evalScripts: true
176
- });
177
- },
178
-
179
- submitTranslation: function() {
180
- Tr8n.Effects.hide('tr8n_translator_translation_container');
181
- Tr8n.Effects.hide('tr8n_translator_buttons_container');
182
- Tr8n.Effects.show('tr8n_translator_spinner');
183
- Tr8n.Effects.submit('tr8n_translator_form');
184
- },
185
-
186
- submitViewingUserDependency: function() {
187
- Tr8n.element('tr8n_translator_translation_has_dependencies').value = "true";
188
- this.submitTranslation();
189
- },
190
-
191
- submitDependencies: function() {
192
- Tr8n.Effects.hide('tr8n_translator_buttons_container');
193
- Tr8n.Effects.hide('tr8n_translator_dependencies_container');
194
- Tr8n.Effects.show('tr8n_translator_spinner');
195
- Tr8n.element('tr8n_translator_form').action = '/tr8n/translations/permutate';
196
- Tr8n.Effects.submit('tr8n_translator_form');
197
- },
198
-
199
- translate: function(label, callback, opts) {
200
- opts = opts || {}
201
- Tr8n.Utils.ajax('/tr8n/language/translate', {
202
- method: 'post',
203
- parameters: {
204
- label: label,
205
- description: opts.description,
206
- tokens: opts.tokens,
207
- options: opts.options,
208
- language: opts.language
209
- },
210
- onSuccess: function(r) {
211
- if(callback) callback(r.responseText);
212
- }
213
- });
214
- },
215
-
216
- translateBatch: function(phrases, callback) {
217
- Tr8n.Utils.ajax('/tr8n/language/translate', {
218
- method: 'post',
219
- parameters: {phrases: phrases},
220
- onSuccess: function(r) {
221
- if (callback) callback(r.responseText);
222
- }
223
- });
224
- },
225
-
226
- processSuggestedTranslation: function(response) {
227
- if (response == null ||response.data == null || response.data.translations==null || response.data.translations.length == 0)
228
- return;
229
- var suggestion = response.data.translations[0].translatedText;
230
- if (this.suggestion_tokens) {
231
- var tokens = this.suggestion_tokens.split(",");
232
- this.suggestion_tokens = null;
233
- for (var i=0; i<tokens.length; i++) {
234
- suggestion = Tr8n.Utils.replaceAll(suggestion, "(" + i + ")", tokens[i]);
235
- }
236
- }
237
- Tr8n.element("tr8n_translation_suggestion_" + this.translation_key_id).innerHTML = suggestion;
238
- Tr8n.element("tr8n_google_suggestion_container_" + this.translation_key_id).style.display = "block";
239
- var suggestion_section = Tr8n.element('tr8n_google_suggestion_section');
240
- if (suggestion_section) suggestion_section.style.display = "block";
241
- },
242
-
243
- suggestTranslation: function(translation_key_id, original, tokens, from_lang, to_lang) {
244
- if (Tr8n.google_api_key == null) return;
245
-
246
- this.suggestion_tokens = tokens;
247
- this.translation_key_id = translation_key_id;
248
- var new_script = document.createElement('script');
249
- new_script.type = 'text/javascript';
250
- var source_text = escape(original);
251
- var api_source = 'https://www.googleapis.com/language/translate/v2?key=' + Tr8n.google_api_key;
252
- var source = api_source + '&source=' + from_lang + '&target=' + to_lang + '&callback=tr8nTranslator.processSuggestedTranslation&q=' + source_text;
253
- new_script.src = source;
254
- document.getElementsByTagName('head')[0].appendChild(new_script);
255
- }
256
-
257
- }