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

e-commerceopencartPHP

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.

Best Answer

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.

Related Topic