WordPress.org

Support

Support » Plugins and Hacks » qTranslate » [Plugin: qTranslate] Back to default language. Why?

[Plugin: qTranslate] Back to default language. Why?

  • 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/

Viewing 4 replies - 1 through 4 (of 4 total)
  • rainbow-trance-10 theme.
    wp: 3.4.1
    qtranslate: 2.5.31

    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);

    }

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

    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);
    
    }

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: qTranslate] Back to default language. Why?’ is closed to new replies.
Skip to toolbar