-
Notifications
You must be signed in to change notification settings - Fork 0
/
GTranslationToolbox.module
170 lines (162 loc) · 6.02 KB
/
GTranslationToolbox.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
// $Id$
/**
* @file
* Module for translation service depends on Google Language API.
*/
/**
* Implementation of hook_help()
*/
function GTranslationToolbox_help($path, $arg) {
if($path == 'admin/help#GTranslationToolbox') {
$txt = 'This module provides translation to all languages that Google Language API supports:'
.'<ul>'
.'<li>A block for translation panel -- Google translation tool.</li>'
.'<li>A translate widget for content.</li>'
.'</ul>';
return '<p>'.t($txt).'</p>';
}
}
/**
* Implementation of hook_init().
*/
function GTranslationToolbox_init() {
drupal_set_html_head('<script src="http://www.google.com/jsapi" type="text/javascript"></script>');
}
/**
* Implementation of hook_menu().
*/
function GTranslationToolbox_menu() {
$items['admin/settings/gtranslate'] = array(
'title' => 'Google Translating Tool settings',
'description' => 'Configure translation tools.',
'page callback' => 'drupal_get_form',
'page arguments' => array('gtranslation_admin_settings_form'),
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
);
/*$items['node/%node/gtranslate'] = array(
'title' => 'Translate',
'page callback' => 'gtranslate',
'page arguments' => array(1, 'node'),
'access arguments'=> array('access content'),
'type' => MENU_LOCAL_TASK,
'weight' => 100,
);*/
/*$items['node/%node'] = array(
'title' => 'Translate',
'page callback' => 'gtranslate',
'page arguments' => array(1, 'node'),
'access arguments'=> array('access content'),
'type' => MENU_LOCAL_TASK,
'weight' => 100,
);*/
return $items;
}
function gtranslate($node){
drupal_add_js(drupal_get_path("module","GTranslationToolbox")."/js/auto_translate.js");
drupal_add_js(drupal_get_path("module","GTranslationToolbox").'/js/translation_panel.js');
$content = node_view($node);
$content = "<div id='translate-box' style='margin:10px auto;'>"
."<select name='language-list' id='content-target-translate-language'></select>"
."<button type='button' onclick='content_translate_onclick();'>Translate</button>"
."<button type='button' onclick='content_original_onclick();'>Show Original</button>"
."</div>"
.'<div id="translate-content">'.$content.'</div>'
.'<script type="text/javascript">
$(document).ready(function(){
//load original content
content_HTML = $("#translate-content").html();
});
</script>';
//.'<div id="original-content" style="display:none">'.$content.'</div>';
return $content;
}
/**
* Add translation widget to the content
*/
function add_translation_widget($content){
drupal_add_js(drupal_get_path("module","GTranslationToolbox")."/js/auto_translate.js");
drupal_add_js(drupal_get_path("module","GTranslationToolbox").'/js/translation_panel.js');
$new_content = "<div id='translate-box' style='margin:10px auto;'>"
."<select name='language-list' id='content-target-translate-language'></select>"
."<button type='button' onclick='content_translate_onclick();'>Translate</button>"
."<button type='button' onclick='content_original_onclick();'>Show Original</button>"
."</div>"
.'<div id="translate-content">'.$content.'</div>'
.'<script type="text/javascript">
$(document).ready(function(){
//load original content
content_HTML = $("#translate-content").html();
});
</script>';
//.'<div id="original-content" style="display:none">'.$content.'</div>';
return $new_content;
}
/**
* Implementation of hook_block().
*/
function GTranslationToolbox_block($op = 'list', $delta = 0, $edit = array()){
switch($op){
case 'list':
$blocks[0]['info'] = t('Google translation tool');
$blocks[1]['info'] = t('Whole page translate');
return $blocks;
case 'view':
$module_path = drupal_get_path('module', 'GTranslationToolbox');
drupal_add_js($module_path.'/translation_panel.js');
switch($delta){
case 0:
$blocks['subject'] = t('Translation');
$blocks['content'] = drupal_get_form('Google_Translation_Tool_form');
return $blocks;
case 1:
$blocks['subject'] = t('Translate Page');
$blocks['content'] = '<select name="language-list" id="page-target-translate-language"></select>'
.'<input class="form-submit" onclick="translate_page_onclick()" type="button" value="Translate" />';
return $blocks;
}
}
}
/**
* Implementation of the drupal_get_form function
*/
function Google_Translation_Tool_form(){
$form['translation'] = array(
'#type' => 'fieldset',
'#title' => t('Translate the text user input'),
);
$form['translation']['original_text'] = array(
'#type' => 'textarea',
'#title' => t('Original text'),
'#suffix' => "<select name='language-list' id='text-target-translate-language'></select>"
."<input type='button' id='translate' value='Translate to' onclick='translationtext()' />",
);
$form['translation']['translation_text'] = array(
'#type' => 'textarea',
'#title' => t('Translated copy'),
);
return $form;
}
/** form for set translate tool **/
function gtranslation_admin_settings_form(){
$form['content-translate'] = array(
'#type' => 'radios',
'#title' => t('Content page translate tool bar'),
'#options' => array('enable'=>'Enable', 'disable'=>'Disable'),
'#required' => TRUE,
'#default_value' => variable_get('open_g_translation_widget', 'disable'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
function gtranslation_admin_settings_form_submit($form, &$form_state){
$content = $form_state['values']['content-translate'];
if($content){
variable_set('open_g_translation_widget', $content);
drupal_set_message(t('Saved the configuration'));
}
}