magento - multilingual site + Add store codes to url - want to show flag icons
- by Mustapha George
I want to have a multi-language magento site use a flag image instead of a language selector box for user to select language of page. There is a nice article on this at http://www.atwix.com/magento/replace-language-selector-flag-icons/
Only issue is that we use "Add store codes to url" option. I hacked this code, but it can use some refinement and make it more Magento looking.
<?php if(count($this->getStores())>1): ?>
<div class="form-language">
<div class="langs-wrapper">
<?php foreach ($this->getStores() as $_lang): ?>
<?php if ($_lang->getCode() != 'default'): ?>
<?
$base_url = Mage::getBaseUrl();
// remove language in base url
$base_url = str_replace('/en/' , "" , $base_url);
$base_url = str_replace('/fr/' , "" , $base_url);
$current_url = $this->helper('core/url')->getCurrentUrl();
// take out base url and language code
$rest_of_url = str_replace($base_url , "" , $current_url);
$rest_of_url = str_replace('/en/' , "" , $rest_of_url);
$rest_of_url = str_replace('/fr/' , "" , $rest_of_url);
// assmble new url
$new_url = $base_url . '/' . $_lang->getCode() . '/' . $rest_of_url;
?>
<a class="lang-flag" href="<?php echo $new_url ;?>"><img src="<?php echo $this->getSkinUrl('images/flags/' . $_lang->getCode() . '.png');?>" alt=""></a>
<?php endif;?>
<?php endforeach;?>
</div>
</div>
<?php endif;?>