Hi Harald,
I have finally been able to test this new version, and it is correctly displays all languages (including current) and also toggles between 2 digit and 4 digit code.
<link href="/en/" rel="alternate" type="text/html" hreflang="en-GB" lang="en-GB" title="Home" />
<link href="/us/" rel="alternate" type="text/html" hreflang="en-US" lang="en-US" title="Home" />
<link href="/de/" rel="alternate" type="text/html" hreflang="de" lang="de-DE" title="Startseite" />
<link href="/fr/" rel="alternate" type="text/html" hreflang="fr-FR" lang="fr-FR" title="Accueil" />
<link href="/ca/" rel="alternate" type="text/html" hreflang="fr-CA" lang="fr-CA" title="Accueil" />
<link href="/it/" rel="alternate" type="text/html" hreflang="it" lang="it-IT" title="Pagina iniziale" />
<link href="/es/" rel="alternate" type="text/html" hreflang="es" lang="es-ES" title="Inicio" />
<link href="/ru/" rel="alternate" type="text/html" hreflang="ru" lang="ru-RU" title="Главная" />
<link href="/cn/" rel="alternate" type="text/html" hreflang="zh" lang="zh-CN" title="起始界面" />
The only issue is now thou, is that not all duplicate languages would need to be 4 digits. You still need at least 1 entry from each language to be purely language (2 digit) and which one this is, could differ from user to user.
For instance in the above, the 2 English entries are United States and Great Britain country targeted. Where having
<link href="/en/" rel="alternate" type="text/html" hreflang="en" lang="en-GB" title="Home" />
<link href="/us/" rel="alternate" type="text/html" hreflang="en-US" lang="en-US" title="Home" />
would target the en-US spelling to United States, but the en-UK spelling to anyone else that has their system set to English regardless of country.
Not sure how this could be maintained outside of manually changing it like I did in the version prior to this (code I used below).
} else {
$lang->active = false;
if (($lang->menutitle != '') && ($params->get('alternatetag'))) {
if ($lang->lang_code == 'en-US' || $lang->lang_code == 'fr-CA' ) {
$doc->addHeadLink($lang->link, 'alternate', 'rel', array(
'type' => 'text/html',
'hreflang' => $lang->lang_code,
'lang' => $lang->lang_code,
'title' => $lang->menutitle
));
} else {
$doc->addHeadLink($lang->link, 'alternate', 'rel', array(
'type' => 'text/html',
'hreflang' => substr($lang->lang_code, 0, 2),
'lang' => $lang->lang_code,
'title' => $lang->menutitle
));
}
}
}
Let me know if there is another aspect of it you would like me to test.
Kind Regards,
Jason