Language Switcher: languages link to the main page of the language or translation of current page if there is


Multilingual website Internationalization module and possibly the Entity Translation necessarily have transition to block language versions. This block usually create module Language Switcher add-in or over it-Language Switcher module Dropdown. In these two cases, the links to the translations work differently, to do as you have to allow the hook.

Translated form russian by Bing Translator.

Language Switcher

In a typical configuration module adds the names of all activated languages site. But if the page does not have translation in any language, that language is not a reference and shows the crossed. The same, if you add flags to the module Language Icons-flag also strike out. This is wrong.
In the settings block this module-Switch language (Text user interface)-don't have any options, so you need to write a hook hook_language_switch_links_alter() to add links on languages for which there is no translation of the current page.
Module Language Dropdown does not distinguish yourself, is there a translation or not, so use the following code to your module or theme in template.php file solves the problem.
The proposed below hook for languages that are not translated, the current page, a reference is set to the main page of the language. (And strike out the style remain, you just need to fix in the CSS).

Language Switcher Dropdown

This add-in module has more thoughtful features and settings of the block:
"Show all enabled languages" - If the jackdaw is marked, then the language selection block will show all active languages, and if there is no translation for some-they will refer to the main page of the language version.
"Redirect to home on switch" - this option for any page of the site when choosing the language opens the home page language version, and does not take into account whether there is a transfer of an entity (user, translate material, term). So if your site is small, and most of the pages translated, you might want to consider switching to the language version of the material and do not include this option.

How to make the transition to the translation of the article, the term user, if translated or at home, if there is no translation?

Open transfers materials-very convenient for the administrator and editor, and probably only for 0.5% of site visitors, therefore more often on other CMS links to languages leading to the main page of the language version, as do languages links to translations of materials-hard and nobody needs. But in Drupal is much more efficient and convenient to everything for the user and developer.

Originally checked off "Go home" plugin Language Switcher Dropdown without any customization switches on the transfer, if any, and to the home page of language-if there is no translation of this page. IE works as it should!

But if you include Entity Translation (for example, to translate user profiles), this clever function module does not work, and Language Switcher Dropdown opens foreign interface and original or translated pages-what's wrong: Russian text on a page with an English interface, no need-need to move home.

The next hook solves the problem. When enabled, Entity Translation Language Switcher module Dropdown will address the user either translation if there or at home if there is no translation.

Hook can be used if you are using the Language Switcher block or Language Switcher Dropdown, hook works with language selection links.

Make links to the translations of the current page if exists, or to the language version home page, if no translation of the current page.
  1. /* Implements hook_language_switch_links_alter().
  2.  * drupal_get_path_alias($path = NULL, $path_language = NULL)
  3.  */
  4. function MYMODULE_language_switch_links_alter(&$links, $type, $path) {
  5. global $language;
  6. if ($type == LANGUAGE_TYPE_INTERFACE && isset($links[$language->language])) {
  7. // get languages paths strings and if it is not aliased replace
  8. foreach ($links as $langcode => &$link) {
  9. // if language switcher element is not active,
  10. // create a link to language front
  11. if (!isset($link['href'])) { $link['href'] = '<front>'; }
  12. $linkpath = drupal_get_path_alias($link['href'], $link['language']->language);
  13. if (($link['language']->language != $language->language) && ($linkpath == $link['href'])) {
  14. $link['href'] = '<front>';
  15. }
  16. }
  17. }
  18. }