In frontend how to get which language is active among installed different languages in Open cart?

99封情书 提交于 2019-12-06 15:07:16

问题


I have installed and themed Opencart 1.5.4x with multiple languages (English, Duch, German) on live server. Opencart application works properly with these languages.

When I click on the language link and browse whole site, the content of the site is translated in this language, but how to find out, programatically, which language is active?

I need to show the user which language is currently active.


回答1:


I guess You should call $this->config->get('config_language_id'); within a controller or model to get the ID of currently active language.

That means, if You have implemented Your own language switcher, in Your controller set the language to the template:

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

and then within Your template do something like:

<?php foreach($languages as $language) { ?>
<a href="..." class="lang-select <?php if $language['language_id'] == $active_language_id) echo ' active'; ?>"><?php echo $language['code']; ?></a>
<?php } ?>

I hope this is what You need to solve and that it would help.




回答2:


simple language select code in opencart

<?php $lang = $this->config->get('config_language');
if($lang == 'ru'){
    $locale = 'ru_RU';
} elseif($lang == 'en'){
    $locale = 'en_US';
} ?> 

and

<?php if ($locale) { echo $locale; } ?>



回答3:


use $language_code in your front, it is set by catalog/controller/module/language.php:

$this->data['language_code'] = $this->session->data['language'];



回答4:


I have a similar question: I would like to get current selected language at product page,so I can show different "social share code" for different language at product page.

1)go to /catalog/controller/product/product.php after

 $data['heading_title'] = $product_info['name'];

add

$data['clanguage']  = $this->session->data['language'];

go to /catalog/view/theme/default/template/product/product.tpl

add the following code to where you want it to display.

<?php echo $clanguage; ?>

now,if you select "English" ,it will show "en-gb",if you select "简体中文",it will show "zh-cn".

then I can use "if " and "this value" to show different "social share code" for different language.

hope it will help , by the it works on opencart 2.3.02,and I think it works on opencart2+,3+.



来源:https://stackoverflow.com/questions/15610405/in-frontend-how-to-get-which-language-is-active-among-installed-different-langua

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!