function gtranslate_block in Translate Drupal with GTranslate 6
File
- ./
gtranslate.module, line 16
Code
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++;
}
// Move the default language to the first position and sort
asort($languages);
$languages = array_merge(array(
variable_get('gtranslate_main_lang', 'en') => $languages[variable_get('gtranslate_main_lang', 'en')],
), $languages);
// use redirect method if using Pro or Enterprise
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;
}
}