0

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; ?>
5
  • It's probably some settings. Does it have a proper homepage etc? Commented Sep 2, 2015 at 8:25
  • Ahh wait, I misunderstood. Please post the phtml file with the language switcher. It's probably missing some if else statement Commented Sep 2, 2015 at 8:26
  • @Sander Mangel Yes it has a general homepage for all store views. Test the other languages, they are working fine...!
    – Meez
    Commented Sep 2, 2015 at 8:29
  • 1
    please post the phtml of the language switcher. We'll need som actual code to debug your problem Commented Sep 2, 2015 at 8:32
  • Found it! tl;dr: change storecode to ZH for China. For full explanation see below Commented Sep 2, 2015 at 9:06

1 Answer 1

2

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

2
  • Ok thanks. I will approve your answer. Additional you have to change the flag-name to zh.png (originally it was cn.png).
    – Meez
    Commented Sep 2, 2015 at 9:48
  • Ah you're right. Glad it's solved Commented Sep 2, 2015 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.