English > General Questions

Alternate Meta Tags

<< < (3/3)

jstead:
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.

--- 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="起始界面" />

--- End code ---

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

--- Code: ---  <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" />

--- End code ---
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).

--- Code: --- } 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
));
}
}
}

--- End code ---

Let me know if there is another aspect of it you would like me to test.

Kind Regards,
Jason

Harald Leithner:
oh ok, then the first language should be the 2 digi version?

Harald Leithner:
Attached is a version that do this.

jstead:
Hi Harald,

Works perfectly!
This method is great, as it also gives the user control over which language is the default as its based of the "Language Manager > Content" ordering.

If I moved French Canadian above French in the Language Manager -> content ordering, it switched which got the 2 digit or 4 digit ISO, so this is perfect as different users would have different defaults.
Couldn't test what would happen if there were 3 variations of the same language, but assume anything after the first instance would get the 4 digit ISO as well.

Kind Regards,
Jason

Harald Leithner:
Thx the 1.3.2 is released with this change.

Navigation

[0] Message Index

[*] Previous page

Go to full version