cancel
Showing results for 
Search instead for 
Did you mean: 

Hreflang - Translate output

Hreflang - Translate output

hreflang - Ausgabe übersetzen

Hi Community,

 

I want to include the alternate links (Hreflang) for a multi-store and I have been implemented like this:

<?php
    foreach (Mage::app()->getWebsites() as $website) {
        foreach ($website->getGroups() as $group) {
            $stores = $group->getStores();
            foreach ($stores as $store) {
                if ($store->getCode() == 'de'){
                    $lang = 'de-de';
                } elseif ($store->getCode() == 'es_de'){
                    $lang = 'de-es';
                } elseif ($store->getCode() == 'es'){
                    $lang = 'es-es';
                } elseif ($store->getCode() == 'fr'){
                    $lang = 'fr-fr';
                } elseif ($store->getCode() == 'en'){
                    $lang = 'en-en';
                }
                echo '<link rel="alternate" href="' . $store->getCurrentUrl(false) . '" hreflang="' . $lang . '"/>' . "\n";
            }
        }
    }
?>

 

That works mostly fine. The output looks e.g. like this:

<link rel="alternate" href="myDomain/de/accessories/hammer.html" hreflang="de-de"/>
<link rel="alternate" href="myDomain/es/accessories/hammer.html" hreflang="es-es"/>
<link rel="alternate" href="myDomain/es_de/accessories/hammer.html" hreflang="de-es"/>
<link rel="alternate" href="myDomain/en/accessories/hammer.html" hreflang="en-en"/>
<link rel="alternate" href="myDomain/fr/accessories/hammer.html" hreflang="fr-fr"/>

 

I've the problem that the path is always in the current language - like: /accessories/hammer.html in english. As a result, the links don't reference correctly because the categories and items depending on the language differ.

 

Can anyone say how to get the translated path from getCurrentUrl (false)?

e.g.

<link rel="alternate" href="myDomain/de/accessories/hammer.html" hreflang="en-en"/>

<link rel="alternate" href="myDomain/de/zubehoer/hammer.html" hreflang="de-de"/>

<link rel="alternate" href="myDomain/fr/accessoires/marteau.html" hreflang="fr-fr"/>

...

Tags (1)