qTranslate: Hide untranslated content

I know qTranslate has the option to hide untranslated content, but that doesn’t seem to work. I.e: I have a website with three languages: Dutch, French and English. There is one particular page that has some subpages that are only available in Dutch. I want them to show up on the Dutch website, but hide them completely from the French and English site. Like so:

  • MenuItem1
  • MenuItem2
    • MenuItem2.1
    • MenuItem2.2
  • MenuItem3

So MenuItem2 and it’s subpages are only available in Dutch. I want them hidden on the English/French website.

Read More

Is this possible with qTranslate, or another plugin? Or is there a piece of code that will allow this?

Thanks.

Related posts

Leave a Reply

4 comments

  1. This might help: http://www.gish.se/wg-qtranslate.zip – download and install, then fix plugin, changing:

    foreach($content as $language  => $lang_text) {
             $lang_text = trim($lang_text);
             if(!empty($lang_text)) $languages[] = $language ;
          }
    

    to

    foreach($content as $lang  => $lang_text) {
             $lang_text = trim($lang_text);
             if(!empty($lang_text)) $languages[] = $lang ;
          }
    

    taken from http://www.qianqin.de/qtranslate/forum/viewtopic.php?f=3&t=2958, works in most cases

  2. Little hack in my submenu code:

    function hierarchical_submenu($post) {
        $top_post = $post;
        // If the post has ancestors, get its ultimate parent and make that the top post
        if ($post->post_parent && $post->ancestors) {
            $top_post = get_post(end($post->ancestors));
        }
        // Always start traversing from the top of the tree
        return hierarchical_submenu_get_children($top_post, $post);
    }
    
    function hierarchical_submenu_get_children($post, $current_page) {
        $menu = '';
        // Get all immediate children of this page
        $children = get_pages('child_of=' . $post->ID . '&parent=' . $post->ID . '&sort_column=menu_order&sort_order=ASC');
        if ($children) {
            $menu = "n<ul>n";
            foreach ($children as $child) {
                // If the child is the viewed page or one of its ancestors, highlight it
                if (in_array($child->ID, get_post_ancestors($current_page)) || ($child->ID == $current_page->ID)) {
                    $menu .= '<li class="active"><a href="' . get_permalink($child) . '" class="first-li active">' . $child->post_title . '</a>';
                } else {
                    if (strcmp($child->post_title, " ")) {
                        $menu .= '<li><a href="' . get_permalink($child) . '">' . $child->post_title . '</a>';
                    }
                }
                // If the page has children and is the viewed page or one of its ancestors, get its children
                if (get_children($child->ID) && (in_array($child->ID, get_post_ancestors($current_page)) || ($child->ID == $current_page->ID))) {
                    $menu .= hierarchical_submenu_get_children($child, $current_page);
                }
                $menu .= "</li>n";
            }
            $menu .= "</ul>n";
        }
        return $menu;
    }
    

    Added the

    if (strcmp($child->post_title, " ")) {
                            $menu .= '<li><a href="' . get_permalink($child) . '">' . $child->post_title . '</a>';
                        }
    

    If structure here.

  3. I create a very simple plugin which enables hiding menu items in some languages, but show them on others.
    After installing my plugin and enabling it, you just need to remove the title from the unwanted language, but leave the string in the others.
    For example if you want to show “Company Profile” only in the English menu, but not in the French menu (or any other language), you set the menu item title to: “Company Profile”.
    The default behavior of qTranslate would give you item “Company Profile (English)” in the French menu.
    Enjoy: http://www.hoojima.com/wordpress/qtranslate-remove-menu-item.zip

  4. I did the following in my theme’s functions.php:

    if (function_exists('qtrans_getLanguage')):
    function mytheme_qt_menu_filter($items) {
        $filtered = array();
        foreach ($items as $item) {
            // TODO Not sure what happens when object_id == ID, which happens if
            //      not linking to post (e.g. external link).
            if (qtrans_isAvailableIn($item->object_id, qtrans_getLanguage()))
                $filtered[] = $item;
        }
        return $filtered;
    }
    add_filter('wp_get_nav_menu_items', 'na_qt_menu_filter');
    endif;
    

    It seems to work in my case 🙂