By ar-jan on
I am trying to adapt this piece of code to do the same for a View (display). Below piece of code redirects a node to the frontpage if the node's language is not the current language. I want to do the same for a View if the language (by filter) is not the same as the current language, but I don't know how to do that. I was searching through Views API but no luck (I'm not a programmer). This code is adapted from #274761: Handling missing translations
<?php
function translation_redirect_nodeapi(&$node, $op, $a3 = null, $a4 = null) {
switch ($op) {
case 'view':
// if current language does not match content node language go to frontpage
global $language;
if (!empty($node->language) && $node->language != $language->language) {
drupal_goto(variable_get('site_frontpage', 'node'));
}
}
}
?>
Anybody?
Comments
Have you tried...
Don’t know if this will help…
___________________
It’s in the detaιls…
demonstration portfolio
It probably makes sense, but I don't know how to implement it
Thanks for your help. It probably makes sense, but I don't know how to implement it. I am also not completely sure if a View declares itself to be in a particular language. It would be great if you could try to combine your example with my code.
Well if that's too much work I will find another workaround. I can set two language filters in Views, one for a particular language and another for current language. That solves duplicate content issue, because accessing the view with the 'wrong' current language shows no content. But the View itself (Title) is still displayed. If the same trick as with the node would work for Views it would be much more elegant.