Drupal - 当前页,其他语言

时间:2013-10-09 14:43:28

标签: drupal localization internationalization

我找到了这段代码:

<?php global $language; ?>
<?php global $theme_path; ?>

<ul class="language-switcher-locale-url">
    <?php $languages = language_list() ?>
    <?php foreach($languages as $lang): ?>
    <?php $active = $language->language == $lang->language ? " active" : ""; ?>
    <li class="<?php echo $lang->language ?><?php echo $active ?>">
        <a href="/<?php echo $lang->prefix ?>">
            <img src="/<?php echo $theme_path ?>/images/flags/<?php echo $lang->language ?>.png" alt="<?php echo $lang->language ?>"/>
        </a>
    </li>
    <?php endforeach ?>
</ul>

这会将我从mywebsite.com/de/current_page重定向到选定的语言ex。 mywebsite.com/en

我可以为我的代码做些什么来将我重定向到mywebsite.com/en/current_page

1 个答案:

答案 0 :(得分:2)

你应该尝试使用Drupal提供的url()request_path()函数,也许这样的东西可以工作:

<?php global $language; global $theme_path; $languages = language_list() ?>

<ul class="language-switcher-locale-url">                                                                                                                                                                           
  <?php foreach($languages as $lang): ?>
    <?php $active = $language->language == $lang->language ? " active" : ""; ?>
    <li class="<?php echo $lang->language ?><?php echo $active ?>">
      <a href="<?php echo url(request_path(), array('language' => $lang)); ?>">
        <img src="/<?php echo $theme_path ?>/images/flags/<?php echo $lang->language ?>.png" alt="<?php echo $lang->language ?>"/>
      </a>
    </li>
  <?php endforeach ?>
</ul>