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

断了今生、忘了曾经 提交于 2019-12-04 21:30:16

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.

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; } ?>
Jean-Michel

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

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

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+.

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