WordPress.org

Ready to get started?Download WordPress

Forums

qTranslate
Back to default language. Why? (5 posts)

  1. csaknoriss
    Member
    Posted 1 year ago #

    Query mod.
    ---------
    For example:
    <!--:en-->Index<!--:--><!--:de-->Startseite<!--:--><!--:fr-->Page d'accueil<!--:--><!--:ru-->главная<!--:-->

    <!--:en-->Offices<!--:--><!--:de-->Chirurgie<!--:--><!--:fr-->Salles de consultation<!--:--><!--:ru-->Лечение<!--:-->

    When I go into the German site in German appears, but when I go to the introduction page back to the default language to English. Why?

    http://wordpress.org/extend/plugins/qtranslate/

  2. csaknoriss
    Member
    Posted 1 year ago #

    rainbow-trance-10 theme.
    wp: 3.4.1
    qtranslate: 2.5.31

  3. csaknoriss
    Member
    Posted 1 year ago #

    Solution:

    Actually I have a better solution to the above, reverse all the changes you did above to the functions.php and just add this one function instead:

    // Fix for qTranslate plugin and "Home" menu link reverting back to default language

    if (function_exists('qtrans_convertURL')) {

    function qtrans_in_nav_el($output, $item, $depth, $args) {

    $attributes = !empty($item->attr_title) ? ' title="' . esc_attr($item->attr_title) . '"' : '';

    $attributes .=!empty($item->target) ? ' target="' . esc_attr($item->target) . '"' : '';

    $attributes .=!empty($item->xfn) ? ' rel="' . esc_attr($item->xfn) . '"' : '';

    // Integration with qTranslate Plugin

    $attributes .=!empty($item->url) ? ' href="' . esc_attr( qtrans_convertURL($item->url) ) . '"' : '';

    $output = $args->before;

    $output .= '<a' . $attributes . '>';

    $output .= $args->link_before . apply_filters('the_title', $item->title, $item->ID) . $args->link_after;

    $output .= '';

    $output .= $args->after;

    return $output;

    }

    add_filter('walker_nav_menu_start_el', 'qtrans_in_nav_el', 10, 4);

    }

  4. Ville.andreas
    Member
    Posted 1 year ago #

    Hello, great solution, but i have a question, this just work for HOME? or in general url's?

  5. nataliette
    Member
    Posted 1 year ago #

    Awesome!
    @Ville.andreas Yup it works for my navigation menu for custom post type archives.

    The only problem is that the code outputs an empty <a> tag, e.g.

    <li id="menu-item-76" class="menu-item menu-item-type-post_type_archive menu-item-object-event menu-item-76">
        <a href="http://example.com/"></a>
        <a href="http://example.dev/events/event/?lang=en">Events</a>
    </li>

    I've been trying to modify the code such that I can remove that empty <a> tag but not being successful...

    P/S. here's a code-friendly version of the hack

    // Fix for qTranslate plugin and "Home" menu link reverting back to default language
    // http://wordpress.org/support/topic/plugin-qtranslate-back-to-default-language-why?replies=4#post-3273387
    
    if (function_exists('qtrans_convertURL')) {
    
    	function qtrans_in_nav_el($output, $item, $depth, $args) {
    		$attributes = !empty($item->attr_title) ? ' title="' . esc_attr($item->attr_title) . '"' : '';
    		$attributes .=!empty($item->target) ? ' target="' . esc_attr($item->target) . '"' : '';
    		$attributes .=!empty($item->xfn) ? ' rel="' . esc_attr($item->xfn) . '"' : '';
    
    		// Integration with qTranslate Plugin
    		$attributes .=!empty($item->url) ? ' href="' . esc_attr( qtrans_convertURL($item->url) ) . '"' : '';
    		$output = $args->before;
    		$output .= '<a' . $attributes . '>';
    		$output .= $args->link_before . apply_filters('the_title', $item->title, $item->ID) . $args->link_after;
    		$output .= '';
    		$output .= $args->after;
    
    		return $output;
    	}
    
    	add_filter('walker_nav_menu_start_el', 'qtrans_in_nav_el', 10, 4);
    
    }

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags