View source
<?php
function gtranslate_help($path, $arg) {
$output = '';
switch ($path) {
case 'admin/help#gtranslate':
$output = '<p>' . t("Uses Google power to translate your web site. Author Edvard Ananyan http://gtranslate.net") . '</p>';
break;
}
return $output;
}
function gtranslate_perm() {
return array(
'access onthisdate content',
);
}
function gtranslate_block($op = 'list', $delta = 0) {
if ($op == 'list') {
$block[0]['info'] = t('GTranslate');
return $block;
}
elseif ($op == 'view') {
$block_content = '';
$languages = array(
'en' => 'English',
'ar' => 'Arabic',
'bg' => 'Bulgarian',
'zhCN' => 'Chinese (Simplified)',
'zhTW' => 'Chinese (Traditional)',
'hr' => 'Croatian',
'cs' => 'Czech',
'da' => 'Danish',
'nl' => 'Dutch',
'fi' => 'Finnish',
'fr' => 'French',
'de' => 'German',
'el' => 'Greek',
'hi' => 'Hindi',
'it' => 'Italian',
'ja' => 'Japanese',
'ko' => 'Korean',
'no' => 'Norwegian',
'pl' => 'Polish',
'pt' => 'Portuguese',
'ro' => 'Romanian',
'ru' => 'Russian',
'es' => 'Spanish',
'sv' => 'Swedish',
'ca' => 'Catalan',
'tl' => 'Filipino',
'iw' => 'Hebrew',
'id' => 'Indonesian',
'lv' => 'Latvian',
'lt' => 'Lithuanian',
'sr' => 'Serbian',
'sk' => 'Slovak',
'sl' => 'Slovenian',
'uk' => 'Ukrainian',
'vi' => 'Vietnamese',
'sq' => 'Albanian',
'et' => 'Estonian',
'gl' => 'Galician',
'hu' => 'Hungarian',
'mt' => 'Maltese',
'th' => 'Thai',
'tr' => 'Turkish',
'fa' => 'Persian',
'af' => 'Afrikaans',
'ms' => 'Malay',
'sw' => 'Swahili',
'ga' => 'Irish',
'cy' => 'Welsh',
'be' => 'Belarusian',
'is' => 'Icelandic',
'mk' => 'Macedonian',
'yi' => 'Yiddish',
'hy' => 'Armenian',
'az' => 'Azerbaijani',
'eu' => 'Basque',
'ka' => 'Georgian',
'ht' => 'Haitian Creole',
'ur' => 'Urdu',
);
$flag_map = array();
$i = $j = 0;
foreach ($languages as $lang => $lang_name) {
$flag_map[$lang] = array(
$i * 100,
$j * 100,
);
if ($i == 7) {
$i = 0;
$j++;
}
else {
$i++;
}
}
$flag_map_vertical = array();
$i = 0;
foreach ($languages as $lang => $lang_name) {
$flag_map_vertical[$lang] = $i * 16;
$i++;
}
asort($languages);
$languages = array_merge(array(
variable_get('gtranslate_main_lang', 'en') => $languages[variable_get('gtranslate_main_lang', 'en')],
), $languages);
if (variable_get('gtranslate_pro', 0) or variable_get('gtranslate_enterprise', 0)) {
variable_set('gtranslate_method', 'redirect');
}
if (variable_get('gtranslate_method', 'onfly') == 'google-default') {
$includedLanguages = array();
foreach ($languages as $lang => $language) {
if (variable_get("gtranslate_{$lang}", 0)) {
switch ($lang) {
case 'zhCN':
$includedLanguages[] = 'zh-CN';
break;
case 'zhTW':
$includedLanguages[] = 'zh-TW';
break;
default:
$includedLanguages[] = $lang;
break;
}
}
}
$includedLanguages = implode(',', $includedLanguages);
$block_content = '<div id="google_translate_element"></div>';
$block_content .= '<script type="text/javascript">';
$block_content .= 'function googleTranslateElementInit() {';
$block_content .= 'new google.translate.TranslateElement({';
$block_content .= "pageLanguage: '" . variable_get('gtranslate_main_lang', 'en') . "',";
$block_content .= 'layout: google.translate.TranslateElement.InlineLayout.SIMPLE, autoDisplay: false,';
$block_content .= "includedLanguages: '" . $includedLanguages . "'";
$block_content .= "}, 'google_translate_element');";
$block_content .= '}';
$block_content .= '</script>';
$block_content .= '<script type="text/javascript" src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>';
}
elseif (variable_get('gtranslate_method', 'onfly') == 'onfly') {
$block_content = <<<EOT
<script type="text/javascript">
/* <![CDATA[ */
eval(unescape("eval%28function%28p%2Ca%2Cc%2Ck%2Ce%2Cr%29%7Be%3Dfunction%28c%29%7Breturn%28c%3Ca%3F%27%27%3Ae%28parseInt%28c/a%29%29%29+%28%28c%3Dc%25a%29%3E35%3FString.fromCharCode%28c+29%29%3Ac.toString%2836%29%29%7D%3Bif%28%21%27%27.replace%28/%5E/%2CString%29%29%7Bwhile%28c--%29r%5Be%28c%29%5D%3Dk%5Bc%5D%7C%7Ce%28c%29%3Bk%3D%5Bfunction%28e%29%7Breturn%20r%5Be%5D%7D%5D%3Be%3Dfunction%28%29%7Breturn%27%5C%5Cw+%27%7D%3Bc%3D1%7D%3Bwhile%28c--%29if%28k%5Bc%5D%29p%3Dp.replace%28new%20RegExp%28%27%5C%5Cb%27+e%28c%29+%27%5C%5Cb%27%2C%27g%27%29%2Ck%5Bc%5D%29%3Breturn%20p%7D%28%276%207%28a%2Cb%29%7Bn%7B4%282.9%29%7B3%20c%3D2.9%28%22o%22%29%3Bc.p%28b%2Cf%2Cf%29%3Ba.q%28c%29%7Dg%7B3%20c%3D2.r%28%29%3Ba.s%28%5C%27t%5C%27+b%2Cc%29%7D%7Du%28e%29%7B%7D%7D6%20h%28a%29%7B4%28a.8%29a%3Da.8%3B4%28a%3D%3D%5C%27%5C%27%29v%3B3%20b%3Da.w%28%5C%27%7C%5C%27%29%5B1%5D%3B3%20c%3B3%20d%3D2.x%28%5C%27y%5C%27%29%3Bz%283%20i%3D0%3Bi%3Cd.5%3Bi++%294%28d%5Bi%5D.A%3D%3D%5C%27B-C-D%5C%27%29c%3Dd%5Bi%5D%3B4%282.j%28%5C%27k%5C%27%29%3D%3DE%7C%7C2.j%28%5C%27k%5C%27%29.l.5%3D%3D0%7C%7Cc.5%3D%3D0%7C%7Cc.l.5%3D%3D0%29%7BF%286%28%29%7Bh%28a%29%7D%2CG%29%7Dg%7Bc.8%3Db%3B7%28c%2C%5C%27m%5C%27%29%3B7%28c%2C%5C%27m%5C%27%29%7D%7D%27%2C43%2C43%2C%27%7C%7Cdocument%7Cvar%7Cif%7Clength%7Cfunction%7CGTranslateFireEvent%7Cvalue%7CcreateEvent%7C%7C%7C%7C%7C%7Ctrue%7Celse%7CdoGTranslate%7C%7CgetElementById%7Cgoogle_translate_element2%7CinnerHTML%7Cchange%7Ctry%7CHTMLEvents%7CinitEvent%7CdispatchEvent%7CcreateEventObject%7CfireEvent%7Con%7Ccatch%7Creturn%7Csplit%7CgetElementsByTagName%7Cselect%7Cfor%7CclassName%7Cgoog%7Cte%7Ccombo%7Cnull%7CsetTimeout%7C500%27.split%28%27%7C%27%29%2C0%2C%7B%7D%29%29"))
/* ]]> */
</script>
EOT;
$block_content .= '<style type="text/css">' . "\n";
$block_content .= "<!--\n";
$block_content .= "#goog-gt-tt {display:none !important;}\n\n.goog-te-banner-frame {display:none !important;}\n\n.goog-te-menu-value:hover {text-decoration:none !important;}\n\nbody {top:0 !important;}\n\n#google_translate_element2 {display:none!important;}\n";
$block_content .= "-->\n";
$block_content .= '</style>';
$default_language = variable_get('gtranslate_main_lang', 'en');
$block_content .= <<<EOT
<div id="google_translate_element2"></div>
<script type="text/javascript">function googleTranslateElementInit2() {new google.translate.TranslateElement({pageLanguage: '{<span class="php-variable">$default_language</span>}', autoDisplay: false}, 'google_translate_element2');}</script>
<script type="text/javascript" src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit2"></script>
EOT;
switch (variable_get('gtranslate_look', 'both')) {
case 'both':
$block_content .= '<style type="text/css">' . "\n";
$block_content .= "<!--\n";
$block_content .= "a.gtflag {background-image:url('" . base_path() . drupal_get_path('module', 'gtranslate') . "/gtranslate-files/" . variable_get('gtranslate_flag_size', '16') . "a.png');}\n";
$block_content .= "a.gtflag:hover {background-image:url('" . base_path() . drupal_get_path('module', 'gtranslate') . "/gtranslate-files/" . variable_get('gtranslate_flag_size', '16') . ".png');}\n";
$block_content .= "-->\n";
$block_content .= '</style>';
$i = $j = 0;
foreach ($languages as $lang => $lang_name) {
if (variable_get("gtranslate_{$lang}", 0) == 2) {
list($flag_x, $flag_y) = $flag_map[$lang];
switch ($lang) {
case 'zhCN':
$lang = 'zh-CN';
break;
case 'zhTW':
$lang = 'zh-TW';
break;
default:
break;
}
$block_content .= '<a href="javascript:doGTranslate(\'' . variable_get('gtranslate_main_lang', 'en') . '|' . $lang . '\')" title="' . $lang_name . '" class="gtflag" style="font-size:' . variable_get('gtranslate_flag_size', '16') . 'px;padding:1px 0;background-repeat:no-repeat;background-position:-' . $flag_x . 'px -' . $flag_y . 'px;"><img src="' . base_path() . drupal_get_path('module', 'gtranslate') . '/gtranslate-files/blank.png" height="' . variable_get('gtranslate_flag_size', '16') . '" width="' . variable_get('gtranslate_flag_size', '16') . '" style="border:0;vertical-align:top;" alt="' . $lang_name . '" /></a> ';
}
if ($i == 7) {
$i = 0;
$j++;
}
else {
$i++;
}
}
$block_content .= '<select onchange="doGTranslate(this);">';
$block_content .= '<option value="">Select Language</option>';
$i = 0;
foreach ($languages as $lang => $lang_name) {
if (variable_get("gtranslate_{$lang}", 0)) {
$flag_y = $flag_map_vertical[$lang];
switch ($lang) {
case 'zhCN':
$lang = 'zh-CN';
break;
case 'zhTW':
$lang = 'zh-TW';
break;
default:
break;
}
$block_content .= '<option value="' . variable_get('gtranslate_main_lang', 'en') . '|' . $lang . '" style="' . ($lang == variable_get('gtranslate_main_lang', 'en') ? 'font-weight:bold;' : '') . 'background:url(\'' . base_path() . drupal_get_path('module', 'gtranslate') . '/gtranslate-files/16l.png\') no-repeat scroll 0 -' . $flag_y . 'px;padding-left:18px;">' . $lang_name . '</option>';
}
$i++;
}
$block_content .= '</select>';
break;
case 'flags':
$block_content .= '<style type="text/css">' . "\n";
$block_content .= "<!--\n";
$block_content .= "a.gtflag {background-image:url('" . base_path() . drupal_get_path('module', 'gtranslate') . "/gtranslate-files/" . variable_get('gtranslate_flag_size', '16') . "a.png');}\n";
$block_content .= "a.gtflag:hover {background-image:url('" . base_path() . drupal_get_path('module', 'gtranslate') . "/gtranslate-files/" . variable_get('gtranslate_flag_size', '16') . ".png');}\n";
$block_content .= "-->\n";
$block_content .= '</style>';
$i = $j = 0;
foreach ($languages as $lang => $lang_name) {
if (variable_get("gtranslate_{$lang}", 0)) {
list($flag_x, $flag_y) = $flag_map[$lang];
switch ($lang) {
case 'zhCN':
$lang = 'zh-CN';
break;
case 'zhTW':
$lang = 'zh-TW';
break;
default:
break;
}
$block_content .= '<a href="javascript:doGTranslate(\'' . variable_get('gtranslate_main_lang', 'en') . '|' . $lang . '\')" title="' . $lang_name . '" class="gtflag" style="font-size:' . variable_get('gtranslate_flag_size', '16') . 'px;padding:1px 0;background-repeat:no-repeat;background-position:-' . $flag_x . 'px -' . $flag_y . 'px;"><img src="' . base_path() . drupal_get_path('module', 'gtranslate') . '/gtranslate-files/blank.png" height="' . variable_get('gtranslate_flag_size', '16') . '" width="' . variable_get('gtranslate_flag_size', '16') . '" style="border:0;vertical-align:top;" alt="' . $lang_name . '" /></a> ';
}
if ($i == 7) {
$i = 0;
$j++;
}
else {
$i++;
}
}
break;
case 'dropdown':
$block_content .= '<select onchange="doGTranslate(this);">';
$block_content .= '<option value="">Select Language</option>';
$i = 0;
foreach ($languages as $lang => $lang_name) {
$flag_y = $flag_map_vertical[$lang];
if (variable_get("gtranslate_{$lang}", 0)) {
switch ($lang) {
case 'zhCN':
$lang = 'zh-CN';
break;
case 'zhTW':
$lang = 'zh-TW';
break;
default:
break;
}
$block_content .= '<option value="' . variable_get('gtranslate_main_lang', 'en') . '|' . $lang . '" style="' . ($lang == variable_get('gtranslate_main_lang', 'en') ? 'font-weight:bold;' : '') . 'background:url(\'' . base_path() . drupal_get_path('module', 'gtranslate') . '/gtranslate-files/16l.png\') no-repeat scroll 0 -' . $flag_y . 'px;padding-left:18px;">' . $lang_name . '</option>';
}
$i++;
}
$block_content .= '</select>';
break;
default:
break;
}
}
else {
$block_content .= '<script type="text/javascript">';
$block_content .= "/* <![CDATA[ */\n";
if (variable_get('gtranslate_new_window', 0)) {
$block_content .= "function openTab(url) {var form=document.createElement('form');form.method='post';form.action=url;form.target='_blank';document.body.appendChild(form);form.submit();}";
if (variable_get('gtranslate_pro', 0)) {
if (variable_get('gtranslate_analytics', false)) {
$block_content .= "function doGTranslate(lang_pair) {if(lang_pair.value)lang_pair=lang_pair.value;var lang=lang_pair.split('|')[1];_gaq.push(['_trackEvent', 'GTranslate', lang, location.pathname+location.search]);var plang=location.pathname.split('/')[1];if(plang.length !=2 && plang != 'zh-CN' && plang != 'zh-TW')plang='" . variable_get('gtranslate_main_lang', 'en') . "';if(lang == '" . variable_get('gtranslate_main_lang', 'en') . "')openTab(location.protocol+'//'+location.host+location.pathname.replace('/'+plang, '')+location.search);else openTab(location.protocol+'//'+location.host+'/'+lang+location.pathname.replace('/'+plang, '')+location.search);}";
}
else {
$block_content .= "function doGTranslate(lang_pair) {if(lang_pair.value)lang_pair=lang_pair.value;var lang=lang_pair.split('|')[1];var plang=location.pathname.split('/')[1];if(plang.length !=2 && plang != 'zh-CN' && plang != 'zh-TW')plang='" . variable_get('gtranslate_main_lang', 'en') . "';if(lang == '" . variable_get('gtranslate_main_lang', 'en') . "')openTab(location.protocol+'//'+location.host+location.pathname.replace('/'+plang, '')+location.search);else openTab(location.protocol+'//'+location.host+'/'+lang+location.pathname.replace('/'+plang, '')+location.search);}";
}
}
else {
$block_content .= "if(top.location!=self.location)top.location=self.location;";
$block_content .= "window['_tipoff']=function(){};window['_tipon']=function(a){};";
if (variable_get('gtranslate_analytics', false)) {
$block_content .= "function doGTranslate(lang_pair) {if(lang_pair.value)lang_pair=lang_pair.value;if(lang_pair=='')return;if(location.hostname=='" . $_SERVER['HTTP_HOST'] . "' && lang_pair=='" . variable_get('gtranslate_main_lang', 'en') . "|" . variable_get('gtranslate_main_lang', 'en') . "')return;var lang=lang_pair.split('|')[1];_gaq.push(['_trackEvent', 'GTranslate', lang, location.pathname+location.search]);if(location.hostname!='" . $_SERVER['HTTP_HOST'] . "' && lang_pair=='" . variable_get('gtranslate_main_lang', 'en') . "|<?php echo {$mainlang}; ?>')openTab(unescape(gfg('u')));else if(location.hostname=='" . $_SERVER['HTTP_HOST'] . "' && lang_pair!='" . variable_get('gtranslate_main_lang', 'en') . "|" . variable_get('gtranslate_main_lang', 'en') . "')openTab('http://translate.google.com/translate?client=tmpg&hl=en&langpair='+lang_pair+'&u='+escape(location.href));else openTab('http://translate.google.com/translate?client=tmpg&hl=en&langpair='+lang_pair+'&u='+unescape(gfg('u')));}";
}
else {
$block_content .= "function doGTranslate(lang_pair) {if(lang_pair.value)lang_pair=lang_pair.value;if(location.hostname=='" . $_SERVER['HTTP_HOST'] . "' && lang_pair=='" . variable_get('gtranslate_main_lang', 'en') . "|" . variable_get('gtranslate_main_lang', 'en') . "')return;else if(location.hostname!='" . $_SERVER['HTTP_HOST'] . "' && lang_pair=='" . variable_get('gtranslate_main_lang', 'en') . "|<?php echo {$mainlang}; ?>')openTab(unescape(gfg('u')));else if(location.hostname=='" . $_SERVER['HTTP_HOST'] . "' && lang_pair!='" . variable_get('gtranslate_main_lang', 'en') . "|" . variable_get('gtranslate_main_lang', 'en') . "')openTab('http://translate.google.com/translate?client=tmpg&hl=en&langpair='+lang_pair+'&u='+escape(location.href));else openTab('http://translate.google.com/translate?client=tmpg&hl=en&langpair='+lang_pair+'&u='+unescape(gfg('u')));}";
}
$block_content .= 'function gfg(name) {name=name.replace(/[\\[]/,"\\\\[").replace(/[\\]]/,"\\\\]");var regexS="[\\?&]"+name+"=([^&#]*)";var regex=new RegExp(regexS);var results=regex.exec(location.href);if(results==null)return "";return results[1];}';
}
}
else {
if (variable_get('gtranslate_pro', 0)) {
if (variable_get('gtranslate_analytics', false)) {
$block_content .= "function doGTranslate(lang_pair) {if(lang_pair.value)lang_pair=lang_pair.value;var lang=lang_pair.split('|')[1];_gaq.push(['_trackEvent', 'GTranslate', lang, location.pathname+location.search]);var plang=location.pathname.split('/')[1];if(plang.length !=2 && plang != 'zh-CN' && plang != 'zh-TW')plang='" . variable_get('gtranslate_main_lang', 'en') . "';if(lang == '" . variable_get('gtranslate_main_lang', 'en') . "')location.pathname=location.pathname.replace('/'+plang, '');else location.pathname='/'+lang+location.pathname.replace('/'+plang, '');}";
}
else {
$block_content .= "function doGTranslate(lang_pair) {if(lang_pair.value)lang_pair=lang_pair.value;var lang=lang_pair.split('|')[1];var plang=location.pathname.split('/')[1];if(plang.length !=2 && plang != 'zh-CN' && plang != 'zh-TW')plang='" . variable_get('gtranslate_main_lang', 'en') . "';if(lang == '" . variable_get('gtranslate_main_lang', 'en') . "')location.pathname=location.pathname.replace('/'+plang, '');else location.pathname='/'+lang+location.pathname.replace('/'+plang, '');}";
}
}
else {
$block_content .= "if(top.location!=self.location)top.location=self.location;";
$block_content .= "window['_tipoff']=function(){};window['_tipon']=function(a){};";
if (variable_get('gtranslate_analytics', false)) {
$block_content .= "function doGTranslate(lang_pair) {if(lang_pair.value)lang_pair=lang_pair.value;if(lang_pair=='')return;if(location.hostname=='" . $_SERVER['HTTP_HOST'] . "' && lang_pair=='" . variable_get('gtranslate_main_lang', 'en') . "|" . variable_get('gtranslate_main_lang', 'en') . "')return;var lang=lang_pair.split('|')[1];_gaq.push(['_trackEvent', 'GTranslate', lang, location.pathname+location.search]);if(location.hostname!='" . $_SERVER['HTTP_HOST'] . "' && lang_pair=='" . variable_get('gtranslate_main_lang', 'en') . "|" . variable_get('gtranslate_main_lang', 'en') . "')location.href=unescape(gfg('u'));else if(location.hostname=='" . $_SERVER['HTTP_HOST'] . "' && lang_pair!='" . variable_get('gtranslate_main_lang', 'en') . "|" . variable_get('gtranslate_main_lang', 'en') . "')location.href='http://translate.google.com/translate?client=tmpg&hl=en&langpair='+lang_pair+'&u='+escape(location.href);else location.href='http://translate.google.com/translate?client=tmpg&hl=en&langpair='+lang_pair+'&u='+unescape(gfg('u'));}";
}
else {
$block_content .= "function doGTranslate(lang_pair) {if(lang_pair.value)lang_pair=lang_pair.value;if(location.hostname=='" . $_SERVER['HTTP_HOST'] . "' && lang_pair=='" . variable_get('gtranslate_main_lang', 'en') . "|" . variable_get('gtranslate_main_lang', 'en') . "')return;else if(location.hostname!='" . $_SERVER['HTTP_HOST'] . "' && lang_pair=='" . variable_get('gtranslate_main_lang', 'en') . "|" . variable_get('gtranslate_main_lang', 'en') . "')location.href=unescape(gfg('u'));else if(location.hostname=='" . $_SERVER['HTTP_HOST'] . "' && lang_pair!='" . variable_get('gtranslate_main_lang', 'en') . "|" . variable_get('gtranslate_main_lang', 'en') . "')location.href='http://translate.google.com/translate?client=tmpg&hl=en&langpair='+lang_pair+'&u='+escape(location.href);else location.href='http://translate.google.com/translate?client=tmpg&hl=en&langpair='+lang_pair+'&u='+unescape(gfg('u'));}";
}
$block_content .= 'function gfg(name) {name=name.replace(/[\\[]/,"\\\\[").replace(/[\\]]/,"\\\\]");var regexS="[\\?&]"+name+"=([^&#]*)";var regex=new RegExp(regexS);var results=regex.exec(location.href);if(results==null)return "";return results[1];}';
}
}
$block_content .= "\n/* ]]> */\n";
$block_content .= '</script>';
switch (variable_get('gtranslate_look', 'both')) {
case 'both':
$block_content .= '<style type="text/css">' . "\n";
$block_content .= "<!--\n";
$block_content .= "a.gtflag {background-image:url('" . base_path() . drupal_get_path('module', 'gtranslate') . "/gtranslate-files/" . variable_get('gtranslate_flag_size', '16') . "a.png');}\n";
$block_content .= "a.gtflag:hover {background-image:url('" . base_path() . drupal_get_path('module', 'gtranslate') . "/gtranslate-files/" . variable_get('gtranslate_flag_size', '16') . ".png');}\n";
$block_content .= "-->\n";
$block_content .= '</style>';
$i = $j = 0;
foreach ($languages as $lang => $lang_name) {
if (variable_get("gtranslate_{$lang}", 0) == 2) {
list($flag_x, $flag_y) = $flag_map[$lang];
switch ($lang) {
case 'zhCN':
$lang = 'zh-CN';
break;
case 'zhTW':
$lang = 'zh-TW';
break;
default:
break;
}
$block_content .= '<a href="javascript:doGTranslate(\'' . variable_get('gtranslate_main_lang', 'en') . '|' . $lang . '\')" title="' . $lang_name . '" class="gtflag" style="font-size:' . variable_get('gtranslate_flag_size', '16') . 'px;padding:1px 0;background-repeat:no-repeat;background-position:-' . $flag_x . 'px -' . $flag_y . 'px;"><img src="' . base_path() . drupal_get_path('module', 'gtranslate') . '/gtranslate-files/blank.png" height="' . variable_get('gtranslate_flag_size', '16') . '" width="' . variable_get('gtranslate_flag_size', '16') . '" style="border:0;vertical-align:top;" alt="' . $lang_name . '" /></a> ';
}
if ($i == 7) {
$i = 0;
$j++;
}
else {
$i++;
}
}
$block_content .= '<select onchange="doGTranslate(this);">';
$block_content .= '<option value="">Select Language</option>';
$i = 0;
foreach ($languages as $lang => $lang_name) {
if (variable_get("gtranslate_{$lang}", 0)) {
$flag_y = $flag_map_vertical[$lang];
switch ($lang) {
case 'zhCN':
$lang = 'zh-CN';
break;
case 'zhTW':
$lang = 'zh-TW';
break;
default:
break;
}
$block_content .= '<option value="' . variable_get('gtranslate_main_lang', 'en') . '|' . $lang . '" style="' . ($lang == variable_get('gtranslate_main_lang', 'en') ? 'font-weight:bold;' : '') . 'background:url(\'' . base_path() . drupal_get_path('module', 'gtranslate') . '/gtranslate-files/16l.png\') no-repeat scroll 0 -' . $flag_y . 'px;padding-left:18px;">' . $lang_name . '</option>';
}
$i++;
}
$block_content .= '</select>';
break;
case 'flags':
$block_content .= '<style type="text/css">' . "\n";
$block_content .= "<!--\n";
$block_content .= "a.gtflag {background-image:url('" . base_path() . drupal_get_path('module', 'gtranslate') . "/gtranslate-files/" . variable_get('gtranslate_flag_size', '16') . "a.png');}\n";
$block_content .= "a.gtflag:hover {background-image:url('" . base_path() . drupal_get_path('module', 'gtranslate') . "/gtranslate-files/" . variable_get('gtranslate_flag_size', '16') . ".png');}\n";
$block_content .= "-->\n";
$block_content .= '</style>';
$i = $j = 0;
foreach ($languages as $lang => $lang_name) {
if (variable_get("gtranslate_{$lang}", 0)) {
list($flag_x, $flag_y) = $flag_map[$lang];
switch ($lang) {
case 'zhCN':
$lang = 'zh-CN';
break;
case 'zhTW':
$lang = 'zh-TW';
break;
default:
break;
}
$block_content .= '<a href="javascript:doGTranslate(\'' . variable_get('gtranslate_main_lang', 'en') . '|' . $lang . '\')" title="' . $lang_name . '" class="gtflag" style="font-size:' . variable_get('gtranslate_flag_size', '16') . 'px;padding:1px 0;background-repeat:no-repeat;background-position:-' . $flag_x . 'px -' . $flag_y . 'px;"><img src="' . base_path() . drupal_get_path('module', 'gtranslate') . '/gtranslate-files/blank.png" height="' . variable_get('gtranslate_flag_size', '16') . '" width="' . variable_get('gtranslate_flag_size', '16') . '" style="border:0;vertical-align:top;" alt="' . $lang_name . '" /></a> ';
}
if ($i == 7) {
$i = 0;
$j++;
}
else {
$i++;
}
}
break;
case 'dropdown':
$block_content .= '<select onchange="doGTranslate(this);">';
$block_content .= '<option value="">Select Language</option>';
$i = 0;
foreach ($languages as $lang => $lang_name) {
$flag_y = $flag_map_vertical[$lang];
if (variable_get("gtranslate_{$lang}", 0)) {
switch ($lang) {
case 'zhCN':
$lang = 'zh-CN';
break;
case 'zhTW':
$lang = 'zh-TW';
break;
default:
break;
}
$block_content .= '<option value="' . variable_get('gtranslate_main_lang', 'en') . '|' . $lang . '" style="' . ($lang == variable_get('gtranslate_main_lang', 'en') ? 'font-weight:bold;' : '') . 'background:url(\'' . base_path() . drupal_get_path('module', 'gtranslate') . '/gtranslate-files/16l.png\') no-repeat scroll 0 -' . $flag_y . 'px;padding-left:18px;">' . $lang_name . '</option>';
}
$i++;
}
$block_content .= '</select>';
break;
default:
break;
}
}
$block['subject'] = 'GTranslate';
$block['content'] = $block_content;
return $block;
}
}
function gtranslate_admin() {
$languages = array(
'en' => 'English',
'ar' => 'Arabic',
'bg' => 'Bulgarian',
'zhCN' => 'Chinese (Simplified)',
'zhTW' => 'Chinese (Traditional)',
'hr' => 'Croatian',
'cs' => 'Czech',
'da' => 'Danish',
'nl' => 'Dutch',
'fi' => 'Finnish',
'fr' => 'French',
'de' => 'German',
'el' => 'Greek',
'hi' => 'Hindi',
'it' => 'Italian',
'ja' => 'Japanese',
'ko' => 'Korean',
'no' => 'Norwegian',
'pl' => 'Polish',
'pt' => 'Portuguese',
'ro' => 'Romanian',
'ru' => 'Russian',
'es' => 'Spanish',
'sv' => 'Swedish',
'ca' => 'Catalan',
'tl' => 'Filipino',
'iw' => 'Hebrew',
'id' => 'Indonesian',
'lv' => 'Latvian',
'lt' => 'Lithuanian',
'sr' => 'Serbian',
'sk' => 'Slovak',
'sl' => 'Slovenian',
'uk' => 'Ukrainian',
'vi' => 'Vietnamese',
'sq' => 'Albanian',
'et' => 'Estonian',
'gl' => 'Galician',
'hu' => 'Hungarian',
'mt' => 'Maltese',
'th' => 'Thai',
'tr' => 'Turkish',
'fa' => 'Persian',
'af' => 'Afrikaans',
'ms' => 'Malay',
'sw' => 'Swahili',
'ga' => 'Irish',
'cy' => 'Welsh',
'be' => 'Belarusian',
'is' => 'Icelandic',
'mk' => 'Macedonian',
'yi' => 'Yiddish',
'hy' => 'Armenian',
'az' => 'Azerbaijani',
'eu' => 'Basque',
'ka' => 'Georgian',
'ht' => 'Haitian Creole',
'ur' => 'Urdu',
);
asort($languages);
$languages = array_merge(array(
variable_get('gtranslate_main_lang', 'en') => $languages[variable_get('gtranslate_main_lang', 'en')],
), $languages);
$form['general'] = array(
'#type' => 'fieldset',
'#title' => t('General Configuration'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['general']['gtranslate_method'] = array(
'#type' => 'radios',
'#title' => t('Translation Method'),
'#default_value' => variable_get('gtranslate_method', 'onfly'),
'#options' => array(
'google-default' => 'Google Default',
'redirect' => 'Redirect',
'onfly' => 'On Fly',
),
'#description' => t("Select which method shall be used when translating the page. On Fly method will show flags and make the translation on the fly without any redirects. Google Default will show only a dropdown provided by Google and it will translate the page on the fly, but you cannot configure it's appearance. Redirect method will redirect the visitor to the translated page. It requires your site to be online, localhost will not work. If the Pro version is installed it will use SEF URLs and keep the visitor on your domain, also it can work on localhost."),
'#required' => TRUE,
);
$form['general']['gtranslate_pro'] = array(
'#type' => 'checkbox',
'#title' => t('Operate with Pro version'),
'#default_value' => variable_get('gtranslate_pro', 0),
'#description' => t("If you have Pro version installed you need to check this box. Find out more on <a href=http://gtranslate.net/?xyz=1002 target=_blank>http://gtranslate.net</a>"),
);
$form['general']['gtranslate_enterprise'] = array(
'#type' => 'checkbox',
'#title' => t('Operate with Enterprise version'),
'#default_value' => variable_get('gtranslate_enterprise', 0),
'#description' => t("If you have Enterprise version configured you need to check this box. Find out more on <a href=http://gtranslate.net/?xyz=1002 target=_blank>http://gtranslate.net</a>"),
);
$form['general']['gtranslate_analytics'] = array(
'#type' => 'checkbox',
'#title' => t('Analytics'),
'#default_value' => variable_get('gtranslate_analytics', 0),
'#description' => t("If you have Google Analytics new code on your site (_gaq). You can enable this which will allow you to see translation events in Google Analytics -> Content -> Event Tracking. Note: Will not work if you use Google Default translation method."),
);
$form['general'][''] = array(
'#type' => 'markup',
'#value' => '<h3>Tour Video</h3>
<iframe src="http://player.vimeo.com/video/30132555?title=1&byline=0&portrait=0" width="568" height="360" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
<p>If you would like to <i>edit translations manually</i> and have <i>SEF URLs</i> (http://domain.com<u>/es/</u>, http://domain.com<u>/fr/</u>, http://domain.com<u>/it/</u>, etc.) for translated languages or you want your <i>translated pages to be indexed</i> in search engines to <i>increase international traffic</i> you may consider <a href="http://gtranslate.net/features?xyz=1002" target="_blank">GTranslate Pro</a> version.</p>
<h3>Translation Delivery Network</h3>
<iframe src="http://player.vimeo.com/video/38686858?title=1&byline=0&portrait=0" width="568" height="360" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
<p>If you would like to use our next generation <i>cloud service</i> which will allow you to <i>host your languages</i> on top level country domain name (ccTLD) to <i>rank higher</i> on local search engines results you may consider <a href="http://gtranslate.net/features?xyz=1002" target="_blank">GTranslate Enterprise</a> a <a href="http://gtranslate.net/translation-delivery-network" target="_blank">Translation Delivery Network</a>. In that case for example for Spanish you can have <u>es.domain.com</u> or <u>domain.es</u> if you own it.</p>',
);
$form['appearance'] = array(
'#type' => 'fieldset',
'#title' => t('Appearance Configuration'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['appearance']['gtranslate_look'] = array(
'#type' => 'select',
'#title' => t('Look'),
'#default_value' => variable_get('gtranslate_look', 'both'),
'#size' => 1,
'#options' => array(
'both' => 'Both',
'flags' => 'Flags',
'dropdown' => 'Dropdown list',
),
'#description' => t("Select the look of the module."),
'#required' => TRUE,
);
$form['appearance']['gtranslate_flag_size'] = array(
'#type' => 'radios',
'#title' => t('Flag Size'),
'#default_value' => variable_get('gtranslate_flag_size', '16'),
'#options' => array(
'16' => '16',
'24' => '24',
'32' => '32',
),
'#description' => t("Select the flag size in pixels."),
'#required' => TRUE,
);
$form['appearance']['gtranslate_new_window'] = array(
'#type' => 'checkbox',
'#title' => t('Open translated page in a new window'),
'#default_value' => variable_get('gtranslate_new_window', 0),
'#description' => t("The translated page will appear in a new window."),
);
$form['language'] = array(
'#type' => 'fieldset',
'#title' => t('Language Configuration'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['language']['gtranslate_main_lang'] = array(
'#type' => 'select',
'#title' => t('Main Language'),
'#default_value' => variable_get('gtranslate_main_lang', 'en'),
'#size' => 1,
'#options' => $languages,
'#description' => t("Your sites main language"),
'#required' => TRUE,
);
$languages_flags = array(
'en',
'fr',
'de',
'it',
'pt',
'ru',
'es',
);
foreach ($languages as $lang => $language) {
$form['language']["gtranslate_{$lang}"] = array(
'#type' => 'radios',
'#title' => t("Show {$language}"),
'#default_value' => variable_get("gtranslate_{$lang}", in_array($lang, $languages_flags) ? 2 : 1),
'#options' => array(
1 => 'Yes',
0 => 'No',
2 => 'As a flag',
),
'#description' => t("Show {$language} in the language list"),
'#required' => TRUE,
);
}
return system_settings_form($form);
}
function gtranslate_menu() {
$items = array();
$items['admin/settings/gtranslate'] = array(
'title' => 'GTranslate',
'description' => 'GTranslate module settings control',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'gtranslate_admin',
),
'access arguments' => array(
'access administration pages',
),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}