Question

On my website: if i switch to Chinese language the flag is not changing in the language switcher? The other languages are working fine. E.g. if you switch to French, its showing the French flag...

This is the language.phtml i am using:

<?php if(count($this->getStores())>1): ?>
<div class="polyglot-language-switcher" data-grid-columns="1" data-anim-effect="fade" data-open-mode="click" data-anim-speed="0.1" >
    <ul style="display: none">
        <?php foreach ($this->getStores() as $_lang):?>
                <li><a href="<?php echo $_lang->getCurrentUrl() ?>" title="<?php echo $this->htmlEscape($_lang->getName()) ?>" data-lang-id="<?php echo $this->htmlEscape($_lang->getCode()) ?>"><img src="<?php echo $this->getSkinUrl('images/flags/' . $_lang->getCode() . '.png');?>" alt=""> <?php echo $this->htmlEscape($_lang->getName()) ?></a></li>
        <?php endforeach;?>
    </ul>
</div>
<?php endif; ?>
Was it helpful?

Solution

Digging through your javascript files I found this piece

    $j('.polyglot-language-switcher').polyglotLanguageSwitcher({
        selectedLang: function () {
            return $j('html').attr('lang');
        }
    });

Which basically uses the lang attribute of the HTML tag to set the current language. Testing this on several stores the language is always set correctly.

<html lang="en" id="top" class="no-js"> for English, <html lang="en" id="top" class="no-js"> for French... But for Chinese <html lang="zh" id="top" class="no-js">

And since you're using the code CN but the language is ZH it doesn't match.

ZH is the ISO2 language code that Magento uses while the language switcher uses the store codes you've provided. The quickest and cleanest solution is to simply change the storecode to ZH. Any other solution would require a hard coded rewrite of the code

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top