In my project I have to display the webshop in two languages.
By default you can choose languages with the following code in:
app/design/frontend/base/default/template/page/switch/language.phtml
<?php if(count($this->getStores())>1): ?>
<div class="form-language">
<label for="select-language"><?php echo $this->__('Your Language:') ?></label>
<select id="select-language" title="<?php echo $this->__('Your Language') ?>" onchange="window.location.href=this.value">
<?php foreach ($this->getStores() as $_lang): ?>
<?php $_selected = ($_lang->getId() == $this->getCurrentStoreId()) ? ' selected="selected"' : '' ?>
<option value="<?php echo $_lang->getCurrentUrl() ?>"<?php echo $_selected ?>><?php echo $this->htmlEscape($_lang->getName()) ?></option>
<?php endforeach; ?>
</select>
</div>
<?php endif; ?>
This of course displaya a select box with the options being all the languages.
I however want to change this so that it become seperate links.
I just don’t really know how to do this.
This is what I have now.
<?php if(count($this->getStores())>1): ?>
<div class="form-language">
<?php foreach ($this->getStores() as $_lang):?>
<a href="" title=""><?php echo $this->htmlEscape($_lang->getName()) ?></a>
<?php endforeach;?>
</div>
<?php endif; ?>
PS: I did not change this in the default magento code. I am working in app/design/frontend/default/projectname/template/page/switch/language.phtml.
So I managed to get this working by myself with this code:
<?php if(count($this->getStores())>1): ?>
<div class="form-language">
<?php foreach ($this->getStores() as $_lang):?>
<a href="<?php echo Mage::getUrl() . '?___store=' . $_lang->getId()?>" title=""><?php echo $this->htmlEscape($_lang->getName()) ?></a>
<?php endforeach;?>
</div>
<?php endif; ?>
But now when I switch language. It redirects to the home page.
I found I should use:
$_lang->getCurrentUrl()
But I have no idea where to place this in my code.
You’re very close, you just need to include the URL!