WordPress.org

Forums

Customizr
[resolved] qTranslate autodetection is not working (45 posts)

  1. iber4
    Member
    Posted 1 year ago #

    Hello all,

    I got an issue in my web, customizr theme with qTranslate installed is not recognizing the web browser lang.

    It did in some point, but it was never flawless. It's kinda buggy or it depends how I type the domain, with or without the http://www... I really can't tell.

    Fact is that I got English by default, but using ES browser it doesn't catch it, so I need to type the /es at the end, and then it works fine, until I clic Inicio (Home) and gets backs to English again, it never happened the other way around.

    Any setting or something I'm missing?

    Thanks!

  2. ElectricFeet
    Member
    Posted 1 year ago #

    I was going to say that you'd be better asking in the qTranslate forum, but there are so many unanswered questions there...

    Looking back, though, there are lots of people asking the same question: https://www.google.com/?hl=en#hl=en&q=qTranslate+returns+to+english+home And lots of answers to browse through too.

  3. iber4
    Member
    Posted 1 year ago #

    Thank you ElectricFeet you are always welcome.

    Yes, I did ask several days ago in the qTranslate forum, not any answer.

    Also, I made my research of-course, same results, old hacks or responses that lead to nothing.

    Any alternative to qTranslate??? I mean if auto-detection isn't working for anybody, this plugin is useless. :-(

    What about WPML?

    THX!!!

  4. ElectricFeet
    Member
    Posted 1 year ago #

    I think WPML is paid. I can't remember if it plays ball with the Customizr front page.

    Seeing if Polylang is fully compatible with the Customizr front page is on my list of things to do. And the author has tried to make it so.

    Thinking further: If you set up a WP page called "Home/Inicio" and make that your Customizr front page, what happens? Does that fix it? My thinking says it should, but you may not be able to get the right combination of home/blog page to make it work.

  5. iber4
    Member
    Posted 1 year ago #

    I mean, auto-detection doesn't work... It's beyond the (Home/Inicio) issue.

    It may be cookies, hacks, etc. But it's a qTranslate deal.

    If auto-detection works I may do with it.

    What's your opinion???

  6. d4z_c0nf
    Member
    Posted 1 year ago #

    Yes it does, if he uses a static front-page.
    Don't know about autodetection, for sure isn't a customizr problem..

  7. iber4
    Member
    Posted 1 year ago #

    customizr seems to be fine, but in the other hand, qTranslate is the creator recommendation.

    So, I need something to autodetect the browser language and gets with it.

    No big deal, it just not working.

  8. d4z_c0nf
    Member
    Posted 1 year ago #

    To me it works if I use this option: Use Query Mode (?lang=en)
    Doesn't work if I use other options, but I don't use pretty permalinks.

  9. iber4
    Member
    Posted 1 year ago #

    OK let me try that and I'll you know.

  10. iber4
    Member
    Posted 1 year ago #

    Nop, it doesn't work... Same behaviour.

  11. ElectricFeet
    Member
    Posted 1 year ago #

    Did you try what I suggested above?

  12. iber4
    Member
    Posted 1 year ago #

    I did, this is my response:
    - Nop, it doesn't work... Same behaviour. -

  13. ElectricFeet
    Member
    Posted 1 year ago #

    Ah, OK, I thought you were responding to d4z_c0nf.

  14. iber4
    Member
    Posted 1 year ago #

    Do something, try it for me, you may see the behaviour:

    kamyacademy.com

    THANKS!

  15. ElectricFeet
    Member
    Posted 1 year ago #

    What do you have in the menu item for home / inicio? That is, in Appearance > Menu? It should say something like:
    <!--:en-->Home<!--:--><!--:es-->Inicio<!--:-->

  16. iber4
    Member
    Posted 1 year ago #

    ../wp-admin/nav-menus.php

    This is what I got:

    [:en]Home[:es]Inicio

  17. iber4
    Member
    Posted 1 year ago #

    Just changed to <!--:en-->Home<!--:--><!--:es-->Inicio<!--:-->

    Nothing happened :-(

  18. ElectricFeet
    Member
    Posted 1 year ago #

    OK, let's get back to basics:

    Your case (? please confirm ?)—with a blog on the front page
    I'm assuming that you are entering the "Home/Inicio" link in your menu. You have no "Home/Inicio" page, right? So this is just a menu item that you are adding as a link in Appearance > Menus?

    If so, there is no qTranslate involvement at all. "Home/Inicio" is just a navigation label, which—because of qTranslate shortcodes—happens to come out in the right language, but is simply a link to your site's url. Both languages point to that link.

    There's no reason to imagine that Customizr or qTranslate should pay any attention. Instead of "Home/Inicio", you could have written "Search/Buscar" and pointed to google.com. So really this is working as designed (don't worry, I still realise it's a problem you need to solve).

    The case where you have a static front page
    If you have a non-blog post home page, with the slider, features and some text on it, then you will have created a page—possibly called "Home/Inicio"—and you've told Customiz'it that this is your "front" page.

    Then adding that page to the menu gives you a link that is respected by qTranslate (that is, you click it on the English pages and you stay in English; you click it on the Italian pages and you stay in Italian). This is because it is a fully-fledged page in it's own right and qTranslate, and the WP menu functionalities know this.

    You could have called this static front page anything you like (not just have called it "home"). Whatever the page, clicking it will still respect the language.

    It would be possible to ask the qTranslate or Customizr developers to change the code to respect the language, but they couldn't do this, as they have no way of knowing whether they are dealing with a fake "home" "page", or the linlk to Google that I described above.

    So, on to solutions:

    Solution 1: Remove "home" altogether. Seriously, it's pretty much a web standard these days to click a logo to get to the home page. The Customizr logo uses standard code to get to the home page and qTranslate hooks into this.

    Solution 2: Nikeo/acub/d4z_c0nf/another programmer comes up with some flashy solution that can be incorporated into Customizr. But this is contingent on them having time for us, of course.

    Solution 3: The qTranslate author comes up with some flashy solution that can be incorporated into qTranslate. But from the looks of his blog, he's trying to reduce his work on the plugin, so this probably isn't going to fly.

    Solution 4: You try this code. I put it in my child's functions.php and it works:

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

    I got this code here.

    The trouble is, I haven't got a clue how it works, which means I'm not a happy bunny giving it as a solution. Well, I do have a bit of a clue: it filters a hook in WP's nav-menu-template.php and gets qTranslate to translate all the menu items using the qtrans_convertURL ... somehow ... waves hands.

    I guess that as it's using WP core code, it's likely to be robust enough to changes, at least in the medium term.

    Solution 5 (maybe): You have your blog on your front page AND on another page. So I guess you selected your blog posts on the front page through Customiz'it and then added posts (with php) on a page called "blog". If you were to do it the other way around (select your blog posts on a page called "blog" through Customiz'it and then add posts (with php) on your static front page, which you call "Home") then qTranslate would respect the language.

    Solution 5 needs more research. It could be a better, more future-proof solution. But I've spent several hours on this already and it's past my bedtime. Over to someone else on this.

  19. d4z_c0nf
    Member
    Posted 1 year ago #

    I think his mainr issue is about autodetection.
    About custom Home menu item, also something simple like this should work:

    if (function_exists('qtrans_convertURL')) {
        add_filter('walker_nav_menu_start_el', 'qtrans_home_mitem', 10, 4);
        function qtrans_home_mitem($output, $item, $depth, $args) {
            return ( get_home_url('http') == $item->url || get_home_url('https') == $item->url) ? str_replace($item->url, qtrans_convertURL($item->url), $output) : $output;
        }
    }
  20. ElectricFeet
    Member
    Posted 1 year ago #

    I knew you'd be able to come up with a Solution 2 :-) Unfortunately, it doesn't work for me :-( Both languages still point to the home page in the default language.

    Is get_home_url('http') correct? I'm way out of my comfort zone on this one.... I also read somewhere that qTranslate hooks into get_blogfino. Not sure if that's relevant.

  21. iber4
    Member
    Posted 1 year ago #

    Thanks you guys, you are kinda big deal.

    Both of you.

    @ElectricFeet I will test each solution, but that doesn't seems to solve the main issue, which is the autodetection problem, which happens in all pages, as you may see.

    @d4z_c0nf Where should I insert this piece of code? What is for exactly?

    THANKS!

  22. iber4
    Member
    Posted 1 year ago #

    As well...

    What about this?

    http://wordpress.org/plugins/qtranslate-slug/

  23. d4z_c0nf
    Member
    Posted 1 year ago #

    @ElectricFeet
    :)
    I used get_home_url 'cause get_bloginfo should be filtered by qtranslate so I couldn't compare that with the item url which is fixed.

    And.. I failed to read the documentation :D So you're not that out :P

    Replace this
    get_home_url('http') == $item->url || get_home_url('https') == $item->url
    with this
    get_home_url(null,'','http') == $item->url

    Let me know if it works, I've tested it in local with no permalinks and with the qtranslate option Use Query Mode (?lang=en) (which, for the record, is the one that for me makes autodetection work ) and looks like good ..

    @iber4
    in your child theme functions.php.
    Simply allows qtranslate to "translate" the url of the menu-item pointing to your home. Doesn't solve autodetection issue!

  24. iber4
    Member
    Posted 1 year ago #

    I made the insertion:

    /*  */
    if (function_exists('qtrans_convertURL')) {
        add_filter('walker_nav_menu_start_el', 'qtrans_home_mitem', 10, 4);
        function qtrans_home_mitem($output, $item, $depth, $args) {
            return ( get_home_url('http') == $item->url || get_home_url('https') == $item->url) ? str_replace($item->url, qtrans_convertURL($item->url), $output) : $output;
        }
    }

    I didn't notice any change at all, what it suppose to do exactly?

  25. d4z_c0nf
    Member
    Posted 1 year ago #

    tested also with qtranslate option Use Pre-Path Mode (Default, puts /en/ in front of URL) + permalinks.
    Seems to work.

    Obviously what posted by ElectricFeet is complete, what I posted is just for the "Home" issue. But still in that case don't know why rebuild $output when you have to just replace a string: $item->url with another string: qtrans_convertURL($item->url).

  26. d4z_c0nf
    Member
    Posted 1 year ago #

    @iber4
    as I said before I made an error, should try this corrected version:

    if (function_exists('qtrans_convertURL')) {
        add_filter('walker_nav_menu_start_el', 'qtrans_home_mitem', 10, 4);
        function qtrans_home_mitem($output, $item, $depth, $args) {
            return ( get_home_url(null,'','http') == $item->url ) ? str_replace($item->url, qtrans_convertURL($item->url), $output) : $output;
        }
    }

    edit:
    gotta go to sleep now.

  27. iber4
    Member
    Posted 1 year ago #

    None.

    When I clic Home it switch to Spanish version... :-( sad.

    http://www.kamyacademy.com/

    It looks like this:
    ...

    * Used everywhere in Customizr. Can pass up to five variables to the filter callback.
    *
    * @since Customizr 3.0
    */
    if( !function_exists( 'tc__f' )) :
        function tc__f ( $tag , $value = null , $arg_one = null , $arg_two = null , $arg_three = null , $arg_four = null , $arg_five = null) {
           return apply_filters( $tag , $value , $arg_one , $arg_two , $arg_three , $arg_four , $arg_five );
        }
    endif;
    
    /* Hack here */
    if (function_exists('qtrans_convertURL')) {
        add_filter('walker_nav_menu_start_el', 'qtrans_home_mitem', 10, 4);
        function qtrans_home_mitem($output, $item, $depth, $args) {
            return ( get_home_url(null,'','http') == $item->url ) ? str_replace($item->url, qtrans_convertURL($item->url), $output) : $output;
        }
    }
    
    /**
    * Fires the theme : constants definition, core classes loading
    *
    *
  28. d4z_c0nf
    Member
    Posted 1 year ago #

    @iber4
    I suspect you have this in your custom menu link "http://www.kamyacademy.com/" , but get_home_url(null,'','http') returns "http://www.kamyacademy.com" so that comparison fails.
    The solution is simple:

    if (function_exists('qtrans_convertURL')) {
        add_filter('walker_nav_menu_start_el', 'qtrans_home_mitem', 10, 4);
        function qtrans_home_mitem($output, $item, $depth, $args) {
            return ( get_home_url(null,'/','http') == $item->url || get_home_url(null,'','http') == $item->url ) ? str_replace($item->url, qtrans_convertURL($item->url), $output) : $output;
        }
    }

    And looks like (reading the commented part in the code you pasted) you copied that snippet in customizr functions.php . Don't change it, you should make a child theme.

  29. ElectricFeet
    Member
    Posted 1 year ago #

    Yay! That works. Thanks d4z_c0nf!

  30. d4z_c0nf
    Member
    Posted 1 year ago #

    :) .
    Well it's a specific hack, I don't like it so much, eheh.

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic