diff --git a/core/includes/language.inc b/core/includes/language.inc index 0892cc4..9c7af7c 100644 --- a/core/includes/language.inc +++ b/core/includes/language.inc @@ -303,6 +303,7 @@ function language_negotiation_method_enabled($method_id, $type = NULL) { function language_negotiation_get_switch_links($type, $path) { $links = FALSE; $negotiation = variable_get("language_negotiation_$type", array()); + $language = language_types_initialize($type); foreach ($negotiation as $method_id => $method) { if (isset($method['callbacks']['language_switch'])) { @@ -313,9 +314,28 @@ function language_negotiation_get_switch_links($type, $path) { $callback = $method['callbacks']['language_switch']; $result = $callback($type, $path); + // Add language specific CSS class as well as support for WCAG 2.0's + // Language of Parts to add language identifiers + // http://www.w3.org/TR/UNDERSTANDING-WCAG20/meaning-other-lang-id.html + foreach ($result as $langcode => $link) { + $result[$langcode]['attributes']['class'][] = 'language-link-' . $langcode; + $result[$langcode]['attributes']['lang'] = $langcode; + } + if (!empty($result)) { // Allow modules to provide translations for specific links. drupal_alter('language_switch_links', $result, $type, $path); + // Add links to alternative versions of this content in other + // languages to the header to improve SEO + foreach($result as $langcode => $link) { + if (isset($link['href']) && $langcode != $language->langcode) { + drupal_add_html_head_link(array( + 'rel' => 'alternate', + 'hreflang' => $langcode, + 'href' => $langcode . '/' . $link['href'], + )); + } + } $links = (object) array('links' => $result, 'method_id' => $method_id); break; } diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php index 02d5139..cadd977 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php @@ -279,7 +279,7 @@ class LanguageUILanguageNegotiationTest extends WebTestBase { // Check that the language switcher active link matches the given browser // language. $args = array(':url' => base_path() . $GLOBALS['script_path'] . $langcode_browser_fallback); - $fields = $this->xpath('//div[@id="block-language-language-interface"]//a[@class="language-link active" and starts-with(@href, :url)]', $args); + $fields = $this->xpath('//div[@id="block-language-language-interface"]//a[@class="language-link language-link-it active" and starts-with(@href, :url)]', $args); $this->assertTrue($fields[0] == $languages[$langcode_browser_fallback]->name, t('The browser language is the URL active language')); // Check that URLs are rewritten using the given browser language.