dongwei1895 2017-12-14 10:08
浏览 86
已采纳

如何将翻译添加到opencart文本字符串?

I'm using Opencart v2.3.0.2. Need help in how to translate some text strings. I've added some links to my header menu (in /catalog/view/theme/mytheme/template/common/header.tpl) using code :

<ul class="static_links">
  <li class="head-links">
    <a href="<?php echo $about_products; ?>">
      <?php echo $text_products; ?>
    </a>
  </li>
  <li class="head-links">
    <a href="<?php echo $contact; ?>">
      <?php echo $text_novosti; ?>
    </a>
  </li>
  <li class="head-links">
    <a href="<?php echo $contact; ?>">
      <?php echo $text_onas; ?>
    </a>
  </li>
</ul>

Also I've added new strings and translations in footer.php (/catalog/language/ru-ru/common/footer.php):

$_['text_products'] = 'О продуктах'; $_['$text_novosti'] = 'Новости'; $_['$text_onas'] = 'О нас';

Finally I've registered that translations in header.php (/catalog/controller/common/header.php):

//New links in menu
$data['text_products']  = $this->language->get('text_products');
$data['text_novosti']  = $this->language->get('text_novosti');        
$data['text_onas']  = $this->language->get('text_onas');

After all when I open page with menu it shows only translation texts for $text_products. In other places it shows only value text_novosti and text_onas. But in should show translations from footer.php instead.

Please help me, how to display translations correctly?

Or maybe there is a way to hardcode texts based on language? Something like:

<?php if ($lang='en') {?> <a href="#">News</a><a href="#">About us</a>
<?php } ?>
НовостиО нас
  • 写回答

1条回答 默认 最新

  • douna3367 2017-12-14 11:25
    关注

    If you want to use your strings in header.tpl, then you must add your strings to:

    catalog/language/ru-ru/common/header.php
    

    not to:

    catalog/language/ru-ru/common/footer.php
    

    If you want to hardcode, in header.php add:

    $data['lang_id'] = $this->config->get('config_language_id');
    

    And in header.tpl:

    <?php if ($lang_id == 1) {?>
        <a href="#">News</a>
        <a href="#">About us</a>
    <?php } else if ($lang_id == 2) {?>
        <a href="#">Новости</a>
        <a href="#">О нас</a>
    <?php } ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失