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

如何将翻译添加到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 } ?>
НовостиО нас

图片转代码服务由CSDN问答提供 功能建议

我正在使用Opencart v2.3.0.2。 如何翻译一些文本字符串的帮助。 我使用代码添加了一些链接到我的标题菜单(在/catalog/view/theme/mytheme/template/common/header.tpl中):

 &lt; ul class  =“static_links”&gt; 
&lt; li class =“head-links”&gt; 
&lt; a href =“&lt;?php echo $ about_products;?&gt;”&gt; 
&lt;?php echo $  text_products;  ?&gt; 
&lt; / a&gt; 
&lt; / li&gt; 
&lt; li class =“head-links”&gt; 
&lt; a href =“&lt;?php echo $ contact;?&gt;  “&gt; 
&lt;?php echo $ text_novosti;  ?&gt; 
&lt; / a&gt; 
&lt; / li&gt; 
&lt; li class =“head-links”&gt; 
&lt; a href =“&lt;?php echo $ contact;?&gt;  “&gt; 
&lt;?php echo $ text_onas;  ?&gt; 
&lt; / a&gt; 
&lt; / li&gt; 
&lt; / ul&gt; 
   
 
 

此外,我添加了新的字符串和翻译 footer.php(/catalog/language/ru-ru/common/footer.php):

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

最后我在header.php中注册了这些翻译(/ catalog / controller / common / header.php):

  //菜单中的新链接
 $ data ['text_products'] = $ this-&gt; language-&gt; get('text_products')  ; 
 $ data ['text_novosti'] = $ this-&gt; language-&gt; get('text_novosti');  
 $ data ['text_onas'] = $ this-&gt; language-&gt; get('text_onas'); 
   
 
 

毕竟当我打开页面时 菜单只显示 $ text_products 的翻译文本。 在其他地方,它只显示值 text_novosti text_onas 。 但是应该显示来自footer.php的翻译。

请帮助我,如何正确显示翻译?

或许有办法 基于语言的硬编码文本? 类似于:

 &lt;?php if($ lang ='en'){?&gt;  &lt; a href =“#”&gt;新闻&lt; / a&gt;&lt; a href =“#”&gt;关于我们&lt; / a&gt; 
&lt;?php}?&gt; 
    
 
НовостиОнас
 
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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 } ?>
    
    点赞 打赏 评论

相关推荐 更多相似问题