最模板 - 外贸网站建设,外贸网站模板

最模板

当前位置: 首页 > Drupal > Drupal教程 >

drupal7语言切换区块

时间:2014-05-29 15:27来源:未知 作者:最模板zuimoban 点击:
位置:locale.module 定义方法: /** * Implements hook_block_info(). */ function locale_block_info() { include_once DRUPAL_ROOT . /includes/language.inc; $block = array(); $info = language_types_info(); foreach (language_types_configurable(FALSE)
位置:locale.module

定义方法:

/**
* Implements hook_block_info().
*/
function locale_block_info() {
  include_once DRUPAL_ROOT . '/includes/language.inc';
  $block = array();
  $info = language_types_info();
  foreach (language_types_configurable(FALSE) as $type) {
    $block[$type] = array(
      'info' => t('Language switcher (@type)', array('@type' => $info[$type]['name'])),
      // Not worth caching.
      'cache' => DRUPAL_NO_CACHE,
    );
  }
  return $block;
}

/**
* Implements hook_block_view().
*
* Displays a language switcher. Only show if we have at least two languages.
*/
function locale_block_view($type) {
  if (drupal_multilingual()) {
    $path = drupal_is_front_page() ? '<front>' : $_GET['q'];
    $links = language_negotiation_get_switch_links($type, $path);

    if (isset($links->links)) {
      drupal_add_css(drupal_get_path('module', 'locale') . '/locale.css');
      $class = "language-switcher-{$links->provider}";
      $variables = array('links' => $links->links, 'attributes' => array('class' => array($class)));
      $block['content'] = theme('links__locale_block', $variables);
      $block['subject'] = t('Languages');
      return $block;
    }
  }
}
(责任编辑:最模板)
------分隔线----------------------------
栏目列表
推荐内容