cancel
Showing results for 
Search instead for 
Did you mean: 

Language switcher improvement

0 Kudos

Language switcher improvement

Feature request from seansan, posted on GitHub Nov 07, 2014

Please find our language switcher improvement for Magento 2 below.

I think this is how it should work. And if you dont want to loose current method then we can create a backend config option that allows both methods

PLease find full transcript here: http://magento.stackexchange.com/questions/42950/magento-multistore-languages-getting-the-locale-lan...

<!-- LANGUAGES BOF -->
<?php if(count($this->getStores())>1): ?>
<?php
$stores = array();
$_current = null;

$languages = Zend_Locale::getTranslationList('language', Mage::app()->getLocale()->getLocaleCode());

foreach ($this->getStores() as $_lang) {

    $_selected = $_selected_option = $_language_name = '';
    $_language_code = substr(Mage::getStoreConfig('general/locale/code', $_lang->getId()),0,2);
    if (isset($languages[$_language_code])) {$_language_name = $languages[$_language_code];} 
    $parts = explode('(', $_language_name);
    $_language_name = trim($parts[0]);

    if ( ($_lang->getId() == $this->getCurrentStoreId()) ) {
     $_current =  $_lang;
     $_current_lang = $_language_name;
     $_selected = ' class="selected"';
     $_selected_option = ' selected="selected"';
    }

    // $stores[] = '<li'. $_selected .'><a style="background-image:url(\''. $this->getSkinUrl('images/flags/'.$_lang->getCode().'.png') .'\');" href="'. $_lang->getCurrentUrl() .'">'. $this->htmlEscape($_lang->getName()) .'</a></li>';
    $stores[] = '<li'. $_selected .'><a style="background-image:url(\''. $this->getSkinUrl('images/flags/'.$_language_code.'.png') .'\');" href="'. $_lang->getCurrentUrl() .'">'. $this->htmlEscape($_language_name) .'</a></li>';
    $select_stores[] = '<option '.$_selected_option.' value="'. $_lang->getCurrentUrl() .'">'. $this->htmlEscape($_lang->getName()) .'</option>';
}

?>
<div class="header-switch language-switch">
    <span><?php echo $this->__('Your Language:') ?>
        <span class="current"><?php echo $this->htmlEscape($_current_lang); ?></span>
    </span>
    <div class="header-dropdown">
        <ul><?php echo implode('', $stores); ?></ul>
    </div>
</div>
2 Comments
apiuser
New Member
Status changed to: Investigating
 
apiuser
New Member

Comment from vpelipenko, posted on GitHub Jan 29, 2015

Internal ticket: MAGETWO-30622