function qtranxf_wp_get_nav_menu_items($items, $menu, $args)
{
    global $q_config;
    $language = $q_config['language'];
    $itemid = 0;
    $menu_order = 0;
    $itemsremoved = array();
    $qtransmenus = array();
    //qtranxf_dbg_log('qtranxf_wp_get_nav_menu_items: count(items)='.count($items).'; args: ', $args);//,true);
    //qtranxf_dbg_log('qtranxf_wp_get_nav_menu_items: count(items)=',count($items));
    foreach ($items as $key => $item) {
        if (isset($item->item_lang)) {
            continue;
        }
        if (isset($itemsremoved[$item->menu_item_parent])) {
            $itemsremoved[$item->ID] = $item;
            unset($items[$key]);
            //remove a child of removed item
            continue;
        }
        $item->item_lang = $language;
        //qtranxf_dbg_log('qtranxf_wp_get_nav_menu_items: $item->url: ',$item->url);
        //qtranxf_dbg_log('qtranxf_wp_get_nav_menu_items: $item: ',$item);
        //qtranxf_dbg_log('qtranxf_wp_get_nav_menu_items: item: '.$item->title.'; p='.$item->menu_item_parent.'; ID='.$item->ID);
        $qtransLangSw = isset($item->url) && stristr($item->url, 'qtransLangSw') !== FALSE;
        if (!$qtransLangSw) {
            $item_title = $item->title;
            if (!empty($item_title)) {
                if (empty($item->post_title) && !qtranxf_isMultilingual($item_title)) {
                    //$item does not have custom menu title, then it fetches information from post_title, but it is already translated with ShowEmpty=false, which gives either valid translation or possibly something like "(English) English Text". We need to translate again and to skip menu item if translation does not exist.
                    switch ($item->type) {
                        case 'post_type':
                            $p = get_post($item->object_id);
                            if ($p && isset($p->post_title_ml)) {
                                $item_title = qtranxf_use_language($language, $p->post_title_ml, false, true);
                            }
                            break;
                        case 'taxonomy':
                            //qtranxf_dbg_log('qtranxf_wp_get_nav_menu_items: taxonomy: $item: ',$item);
                            $term = wp_cache_get($item->object_id, $item->object);
                            if ($term) {
                                //qtranxf_dbg_log('qtranxf_wp_get_nav_menu_items: $term: ',$term);
                                if (isset($q_config['term_name'][$term->name][$language])) {
                                    $item_title = $q_config['term_name'][$term->name][$language];
                                } else {
                                    $item_title = '';
                                }
                                if (!empty($term->description)) {
                                    $item->description = $term->description;
                                }
                            }
                            break;
                    }
                } else {
                    //qtranxf_dbg_log('qtranxf_wp_get_nav_menu_items: $item->title && $item->post_title: $item: ',$item);
                    $item_title = qtranxf_use_language($language, $item_title, false, true);
                }
            }
            //qtranxf_dbg_log('qtranxf_wp_get_nav_menu_items: $item_title: ',$item_title);
            if (empty($item_title)) {
                //qtranxf_dbg_log('removed item: '.$item->title.'; p='.$item->menu_item_parent);
                $itemsremoved[$item->ID] = $item;
                unset($items[$key]);
                //remove menu item with empty title for this language
                continue;
            }
            $item->title = $item_title;
            if ($item->object == 'custom' && !empty($item->url)) {
                if (strpos($item->url, 'setlang=no') === FALSE) {
                    $item->url = qtranxf_convertURL($item->url, $language);
                } else {
                    $item->url = remove_query_arg('setlang', $item->url);
                }
                $i = strpos($item->url, '#?lang=');
                if ($i !== FALSE) {
                    $lang = substr($item->url, $i + 7, 2);
                    $item->url = qtranxf_convertURL('', $lang, false, true);
                    $item->item_lang = $lang;
                }
            }
        }
        $item->post_content = qtranxf_use_language($language, $item->post_content, false, true);
        $item->post_title = qtranxf_use_language($language, $item->post_title, false, true);
        $item->post_excerpt = qtranxf_use_language($language, $item->post_excerpt, false, true);
        $item->description = qtranxf_use_language($language, $item->description, false, true);
        if (isset($item->attr_title)) {
            $item->attr_title = qtranxf_use_language($language, $item->attr_title, false, true);
        }
        if ($itemid < $item->ID) {
            $itemid = $item->ID;
        }
        if ($menu_order < $item->menu_order) {
            $menu_order = $item->menu_order;
        }
        if (!$qtransLangSw) {
            continue;
        }
        $qtransmenus[$key] = $item;
    }
    //qtranxf_dbg_log('qtranxf_wp_get_nav_menu_items: $itemsremoved: ',$itemsremoved);
    if (!empty($itemsremoved)) {
        qtranxf_remove_detached_children($items, $itemsremoved);
    }
    if (!empty($qtransmenus)) {
        foreach ($qtransmenus as $key => $item) {
            $nlang = count($items);
            qtranxf_add_language_menu_item($items, $menu_order, $itemid, $key, $language);
            $nlang = count($items) - $nlang;
            $menu->count += $nlang;
            $menu_order += $nlang;
        }
    }
    //qtranxf_dbg_log('qtranxf_wp_get_nav_menu_items: done: $items: ',$items);
    return $items;
}
function qtranxf_wp_get_nav_menu_items($items, $menu, $args)
{
    global $q_config;
    $language = $q_config['language'];
    $itemid = 0;
    $menu_order = 0;
    $itemsmodified = false;
    $qtransmenus = array();
    //qtranxf_dbg_log('qtranxf_wp_get_nav_menu_items: count(items)=',count($items));
    foreach ($items as $key => $item) {
        //qtranxf_dbg_log('qtranxf_wp_get_nav_menu_items: $item->url: ',$item->url);
        //qtranxf_dbg_log('qtranxf_wp_get_nav_menu_items: $item: ',$item);
        //qtranxf_dbg_log('qtranxf_wp_get_nav_menu_items: item: '.$item->title.'; p='.$item->menu_item_parent.'; ID='.$item->ID);
        $qtransLangSw = isset($item->url) && stristr($item->url, 'qtransLangSw') !== FALSE;
        if (!$qtransLangSw) {
            $item_title = qtranxf_use_language($language, $item->title, false, true);
            if (empty($item_title)) {
                //qtranxf_dbg_echo('removed item: '.$item->title.'; p='.$item->menu_item_parent);
                unset($items[$key]);
                //remove menu item with empty title for this language
                $itemsmodified = true;
                continue;
            }
            $item->title = $item_title;
            if ($item->object == 'custom' && !empty($item->url)) {
                if (strpos($item->url, 'setlang=no') === FALSE) {
                    $item->url = qtranxf_convertURL($item->url, $language);
                } else {
                    $item->url = remove_query_arg('setlang', $item->url);
                }
                $i = strpos($item->url, '#?lang=');
                if ($i !== FALSE) {
                    $lang = substr($item->url, $i + 7, 2);
                    $item->url = qtranxf_convertURL('', $lang, false, true);
                }
            }
        }
        $item->post_content = qtranxf_use_language($language, $item->post_content, false, true);
        $item->post_title = qtranxf_use_language($language, $item->post_title, false, true);
        $item->post_excerpt = qtranxf_use_language($language, $item->post_excerpt, false, true);
        $item->description = qtranxf_use_language($language, $item->description, false, true);
        if (isset($item->attr_title)) {
            $item->attr_title = qtranxf_use_language($language, $item->attr_title, false, true);
        }
        if ($itemid < $item->ID) {
            $itemid = $item->ID;
        }
        if ($menu_order < $item->menu_order) {
            $menu_order = $item->menu_order;
        }
        if (!$qtransLangSw) {
            continue;
        }
        $qtransmenus[$key] = $item;
    }
    if (!empty($qtransmenus)) {
        $nlang = count($q_config['enabled_languages']);
        foreach ($qtransmenus as $key => $item) {
            qtranxf_add_language_menu_item($items, $menu_order, $itemid, $key, $language);
            $menu->count += $nlang;
            $menu_order += $nlang;
        }
    }
    //if(	$itemsmodified ) qtranxf_remove_detached_children($items);
    return $items;
}