Reputation: 322
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.
Upvotes: 1
Views: 7356
Reputation: 121
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+.
Upvotes: 0
Reputation: 1
use $language_code
in your front, it is set by catalog/controller/module/language.php:
$this->data['language_code'] = $this->session->data['language'];
Upvotes: 0
Reputation: 2121
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; } ?>
Upvotes: 0
Reputation: 16055
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.
Upvotes: 6