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 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 虚心请教几个问题,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab