How to have ONLY the language switcher block (no link or icon in the nodes) ?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Frank Steiner’s picture

Would be interested in that too. There's no sense in having both, a global and a per-node language switcher. Sounds like this is just a bug with the needed option still missing in the 6.x branch...?

Jose Reyero’s picture

Title: Language switcher block » Remove language links from nodes and use language switcher block only
Category: support » feature
drewish’s picture

Basically you can add this to your custom module and it'll do the trick. Make sure to replace CUSTOMMODULE with your module's name.

/**
 * Implementation of hook_link_alter() to remove language links.
 */
function CUSTOMMODULE_link_alter(&$links, $node) {
  foreach ($links AS $module => $link) {
    if (preg_match('<^node\_translation\_>', $module)) {
      unset($links[$module]);
    }
  }
}
Frank Steiner’s picture

I hope that someone will that make that a configurable option in the i18n module before I've learned how to write a custom module, because that could take a little longer :-D

phicarre’s picture

I agree completely !!!
I can take the proposition as a temporary solution but it is preferable to have an option into the module.
If we (the users) must change the code ourself then I don't see the advantage of an CMS tool ...
It 's my opinion of course ;-)

x-tin’s picture

Much nicer, just put this in your css file:

a.translation-link{
	display:none;
}

So you don't have to mess with the module itself!

Frank Steiner’s picture

That works fine! Thanks!

phicarre’s picture

Explain please !
The css file of the current theme ? if yes, I am using the DECO theme (style.css) and that doesn't work !

Frank Steiner’s picture

I'm using the default Garland style and had to put it into files/garland-dd4bce3e/style.css because after I had configured the scheme in the drupal config menu, it created this subdirectory in files/ which would overrdige the style.css in /usr/share/drupal/themes/

fletchgqc’s picture

Thanks Drewish,

Spent a while trying to figure out where they get added and how to override it... but your solution will work. Nonetheless I agree with the others, it would be great if some nice person created a configuration option for this.

If a config option is created, there should be an option for teaser view or page view. In my case I want the link flags on page view but not on teaser view.

It's conceivable that a user might want to switch the language of their page, but it's a bit ridiculous to look at teasers in English and then want to read the full article in German!

userid’s picture

css trick works, thanks

phicarre’s picture

Not for me with Deco theme !

nilsja’s picture

i would like to not display the translation-link only in the teaser. In the complete view of the node the link should appear. is that also possible with css?

fletchgqc’s picture

This might help. Otherwise I'm not sure. http://drupal.org/node/170065

ar-jan’s picture

the css display:none works for me too, but two elements remain, like >> and | items that previously separated the translation links.
They're called something like translation_links_en and translation_links_es.
How can I remove those wit CSS?

Siryugo’s picture

Works nice for me to:
Added "a.translation-link{display:none;}" in content section of style.css.
No elements remain.
I'm using admire_gray theme

keuvain33’s picture

If you doesn't want >>

Change just #main by your id

CSS

#main .node .links{
display:none;
}

fax8’s picture

FileSize
684 bytes

Please note that css will only disable displaying. The links html will still be there and you might don't want it.

For example search engines or special css browsers ( browsers for blind persons ) will still show the links and follow them.
If you are concerned about SEO you might think that having two urls on your website which points to the same content (eg: it/node/25 and en/node/25 ) is not a good thing.

This is why I implemented the drewish solution above in a simple module which you find attached.

Hope this helps.

Fabio Varesano

Frank Steiner’s picture

Why don't you submit this as a configure option to the i18n module? That would be great :-)

fletchgqc’s picture

I think the cleanest solution would be to tackle this in core since that's where the links come from. Figure out where in core the links are being added and then enable a configuration variable that causes them to not be added, if set. It would have to be a 7.x feature request. Once we know it's in 7.x, we can settle for using custom modules to strip them out in the meantime.

Whether anyone has the time & motivation to go ahead and do this of course... is another issue.

Pepe Roni’s picture

The language switcher block should switch the interface language and with that, it should switch the content language, too. The language switcher at the bottom of the content should be used to switch the language of the current content only, and nothing else (but indeed it also changes the interface language). I think, that's what this thread is about.

So in short the links should read similar to this:
Language switcher block: mydomain/desired-lang/node/desired-lang-nid
Language switcher at node bottom: mydomain/current-lang/node/desired-lang-nid

where mydomain/lang could also be mylangdomain, depending on language configuration.

Manuel Garcia’s picture

Until someone submits a patch to put this in core, the module approach is definitely the way to go, for a variety of reasons listed above this comment.

Thanks for the code !

-- @Themers -> it takes two seconds to implement this, and being able to do a module is surely a very powerful skill to be have - don't be scared of messing with it!

Tobbetobbe’s picture

Thanks alot Fabio. I added your module and it works fine!

Frank Steiner’s picture

@#21: This wouldn't make any sense. You should not show a german page with a mydomain/en/blabla path. The lang prefix in a path must match the language of the current content for thinks like pathauto to work. And changing the content of the page without changing the interface language cannot work with user defined menus and localization etc.

Pepe Roni’s picture

I don't understand your problem. For switching the interface language, the language switching is for. If I only want to see the translation of the node, I don't see any need to switch the interface language. I can manually enter the node ID in the URL and everything works well: The interface elements are displayed in the language determined by the path and the content elements (including menus) are displayed in the content's language.

What I can enter manually, I would expect the node's language links to do automatically.

Frank Steiner’s picture

Hmm, maybe I misunderstand some terms here. What do you consider the "interface" language? If I switch afrom english to german, I expect to change everything, i.e., the currently shown content, the (used defined) menue which has the menu entry for this content, stuff like the button texts ('search' -> 'Suche') that I use in html forms in the content. Even the primary links menu must localize if I linked the current content from the primary links.

What do you think should stay in english in this case? The administration pages for example?

I guess it was done like this in 5.x, but I'm not sure if this distinction wasn't dropped in 6.x. I think I read sth. like that in a thread, but I'm not sure...

Pepe Roni’s picture

The interface language is determined by the language prefix in the URL or by the domain. The node will be displayed in it's defined language. Thus you can display an English node while the interface language is set to German.

bchoc’s picture

Presuming the themer knows what languages the site will be using, couldn't the themer just add
if ($links[node_translation_en]) unset ($links[node_translation_en]);
for each language needed (this one is for English, obviously) to the top of an overridden theme_links() function?

This seems less work than creating a module to do about the same thing, but maybe I'm way off.

moritzz’s picture

You can easily add the following code to your template.php to filter out all translation links from nodes:

/**
 * Remove translation links.
 */
function YOURTHEMENAME_links(&$links, &$attributes) {
  foreach ($links as $key => &$value) {
    if ($value['attributes']['class'] == 'translation-link') {
      unset($links[$key]);
    }
  }
  return theme_links($links, $attributes);
}

This may not be the best practice because it senses for the class "translation-link" but it works fine for now.

Would be great to have an option in locale to hide these links.

eyalro’s picture

Thanks Fabio! It seems to works.

I am new to this, so it took me a while to understand I need to delete the "_" from the downloaded file....Anyway I installed to my site/all/modules directory and it looks good.

catch’s picture

Assigned: Unassigned » catch

I'll post a patch for the initial feature request later today.

catch’s picture

Status: Active » Needs review
FileSize
1.98 KB

Here's the patch. We add a new field on the i18n settings page, and hide the links if the variable is set.

stella’s picture

Status: Needs review » Reviewed & tested by the community

Patch looks good and works great!

Cheers,
Stella

stella’s picture

FileSize
2.45 KB

Slightly modified patch - it just adds in a call to variable_del() in hook_uninstall() on the new variable.

catch’s picture

Thanks for review and the variable_del() addition, missed that one.

stella’s picture

Issue tags: +i18n sprint
Jose Reyero’s picture

Status: Reviewed & tested by the community » Closed (duplicate)

Committed the patch in #349193: additional language support level that also includes this feature

bbence’s picture

Doesn't really work for me. I can still see the languange links under the node regardless of the Content Type settings. Any ideas why?

Thanks!
Bence

tina1’s picture

Title: Remove language links from nodes and use language switcher block only » italy
Assigned: catch » tina1
tommygun86’s picture

u have an check box (Hide content translation links) in admin/settings/language/i18n for drupal 6 and it hide the language links

Manuel Garcia’s picture

Title: italy » Remove language links from nodes and use language switcher block only
Assigned: tina1 » Unassigned

Reverting title... was assigned to catch also :Z

Anybody’s picture

Issue summary: View changes

Based on the idea from #29 here's the Drupal 7 Version:


/**
* Remove translation links.
*/
function THEME_links($variables) {
  $links = $variables['links'];
  foreach ($links as $key => $value) {
    if (isset($value['attributes']) && $value['attributes']['class'][0] == 'translation-link') {
      unset($variables['links'][$key]);
    }
  }
  return theme_links($variables);
}

You can find my blog article about it here: http://julian.pustkuchen.com/node/601

kingandy’s picture

Alternate ending:

/**
 * Implements hook_preprocess_node()
 */
function MYMODULE_preprocess_node(&$vars) {
  unset($vars['content']['links']['translation']);
}