Jump to content

Language quickchange in Back Office


AndriusS

Recommended Posts

Hey!

 

Site requires some more controls.
Rather than going to the settings and changing the language there, I'd like to have a language switch in a different place.

I've decided on getting the languages in the header.tpl.

So, I've worked out some stuff like this:

                            <a href="?change_lang=4">Lang4</a> 
                            <a href="?change_lang=1">Lang1</a> 
                            <a href="?change_lang=6">Lang6</a> 
                            <a href="?change_lang=5">Lang5</a>

I felt lazy and just updated the admin's index.php file to have this:

if(isset($_GET['change_lang'])) {
    $_GET['id_lang'] = $_GET['change_lang'];
    Tools::switchLanguage();
    Tools::setCookieLanguage();   
}

The language changes at first, BUT it is not saved.

I've skimmed through the methods and they should do that stuff themselves as switchLanguage uses $_GET['id_lang'] and puts it in the cookie. And, well, the second one is just a guess that I might also need it too.

Does not seem to work for me now.

 

Thanks for the help! :)

 

 

 

Link to comment
Share on other sites

hello

why not to use

{$link->getLanguageLink(1)|escape:htmlall}
{$link->getLanguageLink(2)|escape:htmlall}
{$link->getLanguageLink(3)|escape:htmlall}

method than links like <a href="?change_lang=5"> and function with Tools object?

much easier and will work. always :)

Link to comment
Share on other sites

You can override classes file ../classes/controller/AdminController.php in function postProcess() and function initHeader()

something like this ...

class AdminController extends AdminControllerCore
{
    public function postProcess()
    {
        if(Tools::isSubmit('changeLang')) {
            $context = Context::getContext();
            $employee = new Employee($context->employee->id);
            if($employee->id_lang != Tools::getValue('id_lang')) {
                $employee->id_lang = Tools::getValue('id_lang');
                if($employee->update())
                    $this->redirect_after = self::$currentIndex.'&token='.$this->token;
            }
        }
        
        parent::postProcess();
    }
    
    public function initHeader()
    {
        parent::initHeader();

        $this->context->smarty->assign(array(
            'languages' => Language::getLanguages(false),
            'thisIndex' => self::$currentIndex.'&token='.$this->token
            ));
    }
}

And then modify admin theme file header.tpl within <ul id="employee_links"> to add :

{foreach from=$languages item=lang}
    {if $iso_user != $lang.iso_code}
          <li><a href="{$thisIndex}&id_lang={$lang.id_lang}&changeLang">{$lang.iso_code}</a></li>
          <li class="separator"> </li>
    {/if}
{/foreach}
Edited by gonebdg - webindoshop.com (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...