You are here

gtranslate.module in Translate Drupal with GTranslate 7

Same filename and directory in other branches
  1. 8 gtranslate.module
  2. 6 gtranslate.module

File

gtranslate.module
View source
<?php

function gtranslate_help($path, $arg) {
  $output = '';
  switch ($path) {
    case 'admin/help#gtranslate':
      $output = '<p>' . t("Uses Google power to translate your website.") . ' Visit <a href="https://gtranslate.io/?xyz=1002" target="_blank">gtranslate.io</a></p>';
      break;
  }
  return $output;
}

// function gtranslate_help
function gtranslate_block_info() {
  $blocks['gtranslate']['info'] = t('GTranslate');
  $blocks['gtranslate']['cache'] = DRUPAL_NO_CACHE;
  return $blocks;
}

// function gtranslate_block_info
function gtranslate_permission() {
  return array(
    'Modify GTranslate settings' => array(
      'title' => t('Modify GTranslate settings'),
      'description' => t('Administer GTranslate settings.'),
    ),
  );
}

// function gtranslate_permission
function gtranslate_block_view($delta = '') {
  $block_content = '';
  $languages = array(
    'en' => 'English',
    'ar' => 'Arabic',
    'bg' => 'Bulgarian',
    'zh-CN' => 'Chinese (Simplified)',
    'zh-TW' => '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',
    'bn' => 'Bengali',
    'bs' => 'Bosnian',
    'ceb' => 'Cebuano',
    'eo' => 'Esperanto',
    'gu' => 'Gujarati',
    'ha' => 'Hausa',
    'hmn' => 'Hmong',
    'ig' => 'Igbo',
    'jw' => 'Javanese',
    'kn' => 'Kannada',
    'km' => 'Khmer',
    'lo' => 'Lao',
    'la' => 'Latin',
    'mi' => 'Maori',
    'mr' => 'Marathi',
    'mn' => 'Mongolian',
    'ne' => 'Nepali',
    'pa' => 'Punjabi',
    'so' => 'Somali',
    'ta' => 'Tamil',
    'te' => 'Telugu',
    'yo' => 'Yoruba',
    'zu' => 'Zulu',
    'my' => 'Myanmar (Burmese)',
    'ny' => 'Chichewa',
    'kk' => 'Kazakh',
    'mg' => 'Malagasy',
    'ml' => 'Malayalam',
    'si' => 'Sinhala',
    'st' => 'Sesotho',
    'su' => 'Sudanese',
    'tg' => 'Tajik',
    'uz' => 'Uzbek',
    'am' => 'Amharic',
    'co' => 'Corsican',
    'haw' => 'Hawaiian',
    'ku' => 'Kurdish (Kurmanji)',
    'ky' => 'Kyrgyz',
    'lb' => 'Luxembourgish',
    'ps' => 'Pashto',
    'sm' => 'Samoan',
    'gd' => 'Scottish Gaelic',
    'sn' => 'Shona',
    'sd' => 'Sindhi',
    'fy' => 'Frisian',
    'xh' => 'Xhosa',
  );
  $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)) {
        $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="//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="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit2"></script>
EOT;
    switch (variable_get('gtranslate_look', 'flags_dropdown')) {
      case 'flags_dropdown':
      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];
            $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];
            $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];
            $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)) {
            $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 'dropdown_with_flags':
        $gtranslate_main_lang = variable_get('gtranslate_main_lang', 'en');
        $current_language = isset($_SERVER['HTTP_X_GT_LANG']) ? $_SERVER['HTTP_X_GT_LANG'] : $gtranslate_main_lang;
        list($flag_x, $flag_y) = $flag_map[$current_language];
        $block_content .= '<div class="switcher notranslate">';
        $block_content .= '<div class="selected">';
        $block_content .= '<a href="#" onclick="return false;"><span class="gflag" style="background-position:-' . $flag_x . 'px -' . $flag_y . 'px"><img src="' . base_path() . drupal_get_path('module', 'gtranslate') . '/gtranslate-files/blank.png" height="16" width="16" alt="' . $languages[$current_language] . '" /></span>' . $languages[$current_language] . '</a>';
        $block_content .= '</div>';
        $block_content .= '<div class="option">';
        foreach ($languages as $lang => $lang_name) {
          list($flag_x, $flag_y) = $flag_map[$lang];
          if (variable_get('gtranslate_' . $lang, 0) == '2') {
            $block_content .= '<a href="#" onclick="doGTranslate(\'' . $gtranslate_main_lang . '|' . $lang . '\');jQuery(this).parent().parent().find(\'div.selected a\').html(jQuery(this).html());return false;" title="' . $lang_name . '" class="nturl ' . ($current_language == $lang ? ' selected' : '') . '"><span class="gflag" style="background-position:-' . $flag_x . 'px -' . $flag_y . 'px;"><img src="' . base_path() . drupal_get_path('module', 'gtranslate') . '/gtranslate-files/blank.png" height="16" width="16" alt="' . $lang_name . '" /></span>' . $lang_name . '</a>';
          }
        }
        $block_content .= '</div></div>';

        // Adding slider javascript
        drupal_add_js("\n\t\t\t\t    jQuery(document).ready(function() {\n\t\t\t\t\t  jQuery('.switcher .selected').click(function() {if(!(jQuery('.switcher .option').is(':visible'))) {jQuery('.switcher .option').stop(true,true).delay(50).slideDown(800);}});\n\t\t\t\t\t  jQuery('body').not('.switcher .selected').mousedown(function() {if(jQuery('.switcher .option').is(':visible')) {jQuery('.switcher .option').stop(true,true).delay(300).slideUp(800);}});\n\t\t\t\t\t});\n\t\t\t    ", array(
          'type' => 'inline',
          'requires_jquery' => true,
          'scope' => 'footer',
          'weight' => 5,
        ));

        // Adding slider css
        $module_url = base_path() . drupal_get_path('module', 'gtranslate') . '/gtranslate-files';
        drupal_add_css("\n\t\t\t        span.gflag {font-size:16px;padding:1px 0;background-repeat:no-repeat;background-image:url({$module_url}/16.png);}\n\t\t\t        span.gflag img {border:0;margin-top:2px;}\n\t\t\t        .switcher {font-family:Arial;font-size:10pt;text-align:left;cursor:pointer;overflow:hidden;width:163px;line-height:16px;}\n\t\t\t        .switcher a {text-decoration:none;display:block;font-size:10pt;-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;border:none;}\n\t\t\t        .switcher a span.gflag {margin-right:3px;padding:0;display:block;float:left;}\n\t\t\t        .switcher .selected {background:#FFFFFF url({$module_url}/switcher.png) repeat-x;position:relative;z-index:9999;}\n\t\t\t        .switcher .selected a {border:1px solid #CCCCCC;background:url({$module_url}/arrow_down.png) 146px center no-repeat;color:#666666;padding:3px 5px;width:151px;}\n\t\t\t        .switcher .selected a:hover {background:#F0F0F0 url({$module_url}/arrow_down.png) 146px center no-repeat;}\n\t\t\t        .switcher .option {position:relative;z-index:9998;border-left:1px solid #CCCCCC;border-right:1px solid #CCCCCC;border-bottom:1px solid #CCCCCC;background-color:#EEEEEE;display:none;width:161px;-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;}\n\t\t\t        .switcher .option a {color:#000;padding:3px 5px;}\n\t\t\t        .switcher .option a:hover {background:#FFC;}\n\t\t\t        .switcher .option a.selected {background:#FFC;}\n\t\t\t        #selected_lang_name {float: none;}\n\t\t\t        .l_name {float: none !important;margin: 0;}\n\t\t\t    ", array(
          'type' => 'inline',
        ));
        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+'" . request_uri() . "'.replace('/'+plang+'/', '/'));else openTab(location.protocol+'//'+location.host+'/'+lang+'" . request_uri() . "'.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') . "')openTab(location.protocol+'//'+location.host+'" . request_uri() . "'.replace('/'+plang+'/', '/'));else openTab(location.protocol+'//'+location.host+'/'+lang+'" . request_uri() . "'.replace('/'+plang+'/', '/'));}";
        }
      }
      else {
        if (variable_get('gtranslate_enterprise', 0)) {
          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;var lang=lang_pair.split('|')[1];if(typeof _gaq=='undefined')alert('Google Analytics is not installed, please turn off Analytics feature in GTranslate');else _gaq.push(['_trackEvent', 'doGTranslate', lang, location.hostname+'" . request_uri() . "']);var plang=location.hostname.split('.')[0];if(plang.length !=2 && plang.toLowerCase() != 'zh-cn' && plang.toLowerCase() != 'zh-tw')plang='" . variable_get('gtranslate_main_lang', 'en') . "';openTab(location.protocol+'//'+(lang == '" . variable_get('gtranslate_main_lang', 'en') . "' ? '' : lang+'.')+location.hostname.replace('www.', '').replace(RegExp('^' + plang + '\\\\.'), '')+'" . request_uri() . "');}";
          }
          else {
            $block_content .= "function doGTranslate(lang_pair) {if(lang_pair.value)lang_pair=lang_pair.value;if(lang_pair=='')return;var lang=lang_pair.split('|')[1];var plang=location.hostname.split('.')[0];if(plang.length !=2 && plang.toLowerCase() != 'zh-cn' && plang.toLowerCase() != 'zh-tw')plang='" . variable_get('gtranslate_main_lang', 'en') . "';openTab(location.protocol+'//'+(lang == '" . variable_get('gtranslate_main_lang', 'en') . "' ? '' : lang+'.')+location.hostname.replace('www.', '').replace(RegExp('^' + plang + '\\\\.'), '')+'" . request_uri() . "');}";
          }
        }
        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.href='" . request_uri() . "'.replace('/'+plang+'/', '/');else location.href='/'+lang+'" . request_uri() . "'.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.href='" . request_uri() . "'.replace('/'+plang+'/', '/');else location.href='/'+lang+'" . request_uri() . "'.replace('/'+plang+'/', '/');}";
        }
      }
      else {
        if (variable_get('gtranslate_enterprise', 0)) {
          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;var lang=lang_pair.split('|')[1];if(typeof _gaq=='undefined')alert('Google Analytics is not installed, please turn off Analytics feature in GTranslate');else _gaq.push(['_trackEvent', 'doGTranslate', lang, location.hostname+location.pathname+location.search]);var plang=location.hostname.split('.')[0];if(plang.length !=2 && plang.toLowerCase() != 'zh-cn' && plang.toLowerCase() != 'zh-tw')plang='" . variable_get('gtranslate_main_lang', 'en') . "';location.href=location.protocol+'//'+(lang == '" . variable_get('gtranslate_main_lang', 'en') . "' ? '' : lang+'.')+location.hostname.replace('www.', '').replace(RegExp('^' + plang + '\\\\.'), '')+'" . request_uri() . "';}";
          }
          else {
            $block_content .= "function doGTranslate(lang_pair) {if(lang_pair.value)lang_pair=lang_pair.value;if(lang_pair=='')return;var lang=lang_pair.split('|')[1];var plang=location.hostname.split('.')[0];if(plang.length !=2 && plang.toLowerCase() != 'zh-cn' && plang.toLowerCase() != 'zh-tw')plang='" . variable_get('gtranslate_main_lang', 'en') . "';location.href=location.protocol+'//'+(lang == '" . variable_get('gtranslate_main_lang', 'en') . "' ? '' : lang+'.')+location.hostname.replace('www.', '').replace(RegExp('^' + plang + '\\\\.'), '')+'" . request_uri() . "';}";
          }
        }
        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', 'flags_dropdown')) {
      case 'flags_dropdown':
      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];
            $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];
            $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];
            $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)) {
            $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 'dropdown_with_flags':
        $gtranslate_main_lang = variable_get('gtranslate_main_lang', 'en');
        $current_language = isset($_SERVER['HTTP_X_GT_LANG']) ? $_SERVER['HTTP_X_GT_LANG'] : $gtranslate_main_lang;
        list($flag_x, $flag_y) = $flag_map[$current_language];
        $block_content .= '<div class="switcher notranslate">';
        $block_content .= '<div class="selected">';
        $block_content .= '<a href="#" onclick="return false;"><span class="gflag" style="background-position:-' . $flag_x . 'px -' . $flag_y . 'px"><img src="' . base_path() . drupal_get_path('module', 'gtranslate') . '/gtranslate-files/blank.png" height="16" width="16" alt="' . $languages[$current_language] . '" /></span>' . $languages[$current_language] . '</a>';
        $block_content .= '</div>';
        $block_content .= '<div class="option">';
        foreach ($languages as $lang => $lang_name) {
          list($flag_x, $flag_y) = $flag_map[$lang];
          if (variable_get('gtranslate_pro', 0)) {
            $href = $gtranslate_main_lang == $lang ? request_uri() : '/' . $lang . request_uri();
          }
          elseif (variable_get('gtranslate_enterprise', 0)) {
            $href = $gtranslate_main_lang == $lang ? request_uri() : '//' . $lang . '.' . str_replace('www.', '', $_SERVER['HTTP_HOST'] . request_uri());
          }
          if (variable_get('gtranslate_' . $lang, 0) == '2') {
            $block_content .= '<a href="' . $href . '"' . (variable_get('gtranslate_new_window', 0) ? ' target="_blank"' : '') . ' title="' . $lang_name . '" class="nturl ' . ($current_language == $lang ? ' selected' : '') . '"><span class="gflag" style="background-position:-' . $flag_x . 'px -' . $flag_y . 'px;"><img src="' . base_path() . drupal_get_path('module', 'gtranslate') . '/gtranslate-files/blank.png" height="16" width="16" alt="' . $lang_name . '" /></span>' . $lang_name . '</a>';
          }
        }
        $block_content .= '</div></div>';

        // Adding slider javascript
        drupal_add_js("\n\t\t\t\t    jQuery(document).ready(function() {\n\t\t\t\t\t  jQuery('.switcher .selected').click(function() {if(!(jQuery('.switcher .option').is(':visible'))) {jQuery('.switcher .option').stop(true,true).delay(50).slideDown(800);}});\n\t\t\t\t\t  jQuery('body').not('.switcher .selected').mousedown(function() {if(jQuery('.switcher .option').is(':visible')) {jQuery('.switcher .option').stop(true,true).delay(300).slideUp(800);}});\n\t\t\t\t\t});\n\t\t\t    ", array(
          'type' => 'inline',
          'requires_jquery' => true,
          'scope' => 'footer',
          'weight' => 5,
        ));

        // Adding slider css
        $module_url = base_path() . drupal_get_path('module', 'gtranslate') . '/gtranslate-files';
        drupal_add_css("\n\t\t\t        span.gflag {font-size:16px;padding:1px 0;background-repeat:no-repeat;background-image:url({$module_url}/16.png);}\n\t\t\t        span.gflag img {border:0;margin-top:2px;}\n\t\t\t        .switcher {font-family:Arial;font-size:10pt;text-align:left;cursor:pointer;overflow:hidden;width:163px;line-height:16px;}\n\t\t\t        .switcher a {text-decoration:none;display:block;font-size:10pt;-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;border:none;}\n\t\t\t        .switcher a span.gflag {margin-right:3px;padding:0;display:block;float:left;}\n\t\t\t        .switcher .selected {background:#FFFFFF url({$module_url}/switcher.png) repeat-x;position:relative;z-index:9999;}\n\t\t\t        .switcher .selected a {border:1px solid #CCCCCC;background:url({$module_url}/arrow_down.png) 146px center no-repeat;color:#666666;padding:3px 5px;width:151px;}\n\t\t\t        .switcher .selected a:hover {background:#F0F0F0 url({$module_url}/arrow_down.png) 146px center no-repeat;}\n\t\t\t        .switcher .option {position:relative;z-index:9998;border-left:1px solid #CCCCCC;border-right:1px solid #CCCCCC;border-bottom:1px solid #CCCCCC;background-color:#EEEEEE;display:none;width:161px;-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;}\n\t\t\t        .switcher .option a {color:#000;padding:3px 5px;}\n\t\t\t        .switcher .option a:hover {background:#FFC;}\n\t\t\t        .switcher .option a.selected {background:#FFC;}\n\t\t\t        #selected_lang_name {float: none;}\n\t\t\t        .l_name {float: none !important;margin: 0;}\n\t\t\t    ", array(
          'type' => 'inline',
        ));
        break;
      default:
        break;
    }
  }
  $block['subject'] = 'GTranslate';
  $block['content'] = $block_content;
  return $block;
}

// function gtranslate_block_view
function gtranslate_admin() {
  $languages = array(
    'en' => 'English',
    'ar' => 'Arabic',
    'bg' => 'Bulgarian',
    'zh-CN' => 'Chinese (Simplified)',
    'zh-TW' => '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',
    'bn' => 'Bengali',
    'bs' => 'Bosnian',
    'ceb' => 'Cebuano',
    'eo' => 'Esperanto',
    'gu' => 'Gujarati',
    'ha' => 'Hausa',
    'hmn' => 'Hmong',
    'ig' => 'Igbo',
    'jw' => 'Javanese',
    'kn' => 'Kannada',
    'km' => 'Khmer',
    'lo' => 'Lao',
    'la' => 'Latin',
    'mi' => 'Maori',
    'mr' => 'Marathi',
    'mn' => 'Mongolian',
    'ne' => 'Nepali',
    'pa' => 'Punjabi',
    'so' => 'Somali',
    'ta' => 'Tamil',
    'te' => 'Telugu',
    'yo' => 'Yoruba',
    'zu' => 'Zulu',
    'my' => 'Myanmar (Burmese)',
    'ny' => 'Chichewa',
    'kk' => 'Kazakh',
    'mg' => 'Malagasy',
    'ml' => 'Malayalam',
    'si' => 'Sinhala',
    'st' => 'Sesotho',
    'su' => 'Sudanese',
    'tg' => 'Tajik',
    'uz' => 'Uzbek',
    'am' => 'Amharic',
    'co' => 'Corsican',
    'haw' => 'Hawaiian',
    'ku' => 'Kurdish (Kurmanji)',
    'ky' => 'Kyrgyz',
    'lb' => 'Luxembourgish',
    'ps' => 'Pashto',
    'sm' => 'Samoan',
    'gd' => 'Scottish Gaelic',
    'sn' => 'Shona',
    'sd' => 'Sindhi',
    'fy' => 'Frisian',
    'xh' => 'Xhosa',
  );

  // 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);
  $form['general'] = array(
    '#type' => 'fieldset',
    '#title' => t('General Configuration'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['general']['gtranslate_look'] = array(
    '#type' => 'select',
    '#title' => t('Look'),
    '#default_value' => variable_get('gtranslate_look', 'flags_dropdown'),
    '#size' => 1,
    '#options' => array(
      'flags_dropdown' => 'Flags and dropdown',
      'flags' => 'Flags',
      'dropdown' => 'Dropdown',
      'dropdown_with_flags' => 'Nice dropdown with flags',
    ),
    '#description' => t("Select the look of the module."),
    '#required' => TRUE,
  );
  $form['general']['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,
  );
  $form['general']['gtranslate_pro'] = array(
    '#type' => 'checkbox',
    '#title' => t('Sub-directory URL structure'),
    '#default_value' => variable_get('gtranslate_pro', 0),
    '#description' => t('Example: http://example.com/<b>ru</b>/. This feature is available only in paid plans: <a href="https://gtranslate.io/?xyz=1002#pricing" target="_blank">https://gtranslate.io/#pricing</a>'),
  );
  $form['general']['gtranslate_enterprise'] = array(
    '#type' => 'checkbox',
    '#title' => t('Sub-domain URL structure'),
    '#default_value' => variable_get('gtranslate_enterprise', 0),
    '#description' => t('Example: http://<b>es.</b>example.com/. This feature is available only in paid plans: <a href="https://gtranslate.io/?xyz=1002#pricing" target="_blank">https://gtranslate.io/#pricing</a>'),
  );
  $form['general']['gtranslate_flag_size'] = array(
    '#type' => 'radios',
    '#title' => t('Flag Size'),
    '#default_value' => variable_get('gtranslate_flag_size', '16'),
    '#options' => array(
      '16' => '16px',
      '24' => '24px',
      '32' => '32px',
    ),
    '#description' => t("Select the flag size in pixels."),
    '#required' => TRUE,
  );
  $form['general']['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['general']['gtranslate_analytics'] = array(
    '#type' => 'checkbox',
    '#title' => t('Analytics'),
    '#default_value' => variable_get('gtranslate_analytics', 0),
    '#description' => t("If you have Google Analytics _gaq code on your site you can enable this which will allow you to see translation events in Google Analytics -&gt; Content -&gt; Event Tracking."),
  );
  $form['language'] = array(
    '#type' => 'fieldset',
    '#title' => t('Language Configuration'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $languages_flags = array(
    'en',
    'fr',
    'de',
    'it',
    'pt',
    'ru',
    'es',
  );
  $languages_noflags = array(
    'my' => 'Myanmar (Burmese)',
    'ny' => 'Chichewa',
    'kk' => 'Kazakh',
    'mg' => 'Malagasy',
    'ml' => 'Malayalam',
    'si' => 'Sinhala',
    'st' => 'Sesotho',
    'su' => 'Sudanese',
    'tg' => 'Tajik',
    'uz' => 'Uzbek',
    'am' => 'Amharic',
    'co' => 'Corsican',
    'haw' => 'Hawaiian',
    'ku' => 'Kurdish (Kurmanji)',
    'ky' => 'Kyrgyz',
    'lb' => 'Luxembourgish',
    'ps' => 'Pashto',
    'sm' => 'Samoan',
    'gd' => 'Scottish Gaelic',
    'sn' => 'Shona',
    'sd' => 'Sindhi',
    'fy' => 'Frisian',
    'xh' => 'Xhosa',
  );
  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 : (in_array($lang, $languages_noflags) ? 0 : 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_admin
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(
      'Modify GTranslate settings',
    ),
    'type' => MENU_NORMAL_ITEM,
  );
  return $items;
}

// function gtranslate_menu