Following up on https://lists.wikimedia.org/pipermail/wikitech-l/2015-February/080661.html. Quoting:
MediaWiki emits the hreflang attribute on language links, but only as part of the links in the body, and not in the <head> as recommended by Google [1]. The result of this is that Google (and possibly other search engines) doesn't interpret the hreflang attribute for purposes of prioritizing search results in the user's own language. From a contact at Google we asked about this: "we currently don't use those annotations on the links, we need to see the hreflang link-elements in the head in order to understand that connection. The important parts there are the we need to have them in the "head", we need to have them confirmed from the other versions (so DE needs to refer to EN, and EN to DE -- it can't be one-sided), and it needs to be between the canonical URLs. (...) I imagine if you just added the cross-links as you have them in the sidebar as link-elements to the head then you'd be covered." This of course would add some additional payload to pages with lots of language links, but could help avoid results like [2] where the English language version of an article is #1 and the Indonesian one makes no appearance at all. Results vary greatly and it's hard to say how big a problem this is, but even if boosts discoverability of content in the user's language by only 10% or so, that would still be a pretty big win for local content.
Our end goal is that all the variants of a page have the exact same hreflang block in their <head> e.g. for the Menlo article all three variants on the three different language wikipedias would have this exact block:
<link rel="alternate" hreflang="en" href="//en.wikipedia.org/wiki/Menlo,_County_Galway" /> <link rel="alternate" hreflang="ga" href="//ga.wikipedia.org/wiki/Mionloch" /> <link rel="alternate" hreflang="ru" href="//ru.wikipedia.org/wiki/%D0%9C%D0%B5%D0%BD%D0%BB%D0%BE%D1%85_(%D0%B7%D0%B0%D0%BF%D0%B0%D0%B4%D0%BD%D1%8B%D0%B9)" />
I'm new to mediawiki development but did a bit of hacking on the easy parts of this in /includes/OutputPage.php, trying to re-use the array generated for the interwiki language links in the sidebar. Diff attached that uses dummy data for now since I was doing locally. It's just a start lots left to do like get the current page info so we have it as an alternate too, doing this efficiently, and lots of testing. I'm at the limits of my knowledge so will need some help/pointers.
See also: