WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Widget Logic] Multilanguage (7 posts)

  1. luca_melis
    Member
    Posted 5 years ago #

    Hi, I am usnig the plugin qTranslate. Unfortunately I am not skilled with php, is there a conditional tag to make a text widget load only in one language version? Like a text widget in Italian when users choose the Italian version? I've been looking for it but couldn't find any.
    Thanks.

  2. alanft
    Member
    Posted 5 years ago #

    i don't use qTranslate myself, but a quick look through the code shows that when active it provides a function called qtrans_getLanguage() that returns the user's chosen language in the standard two-letter code. this means you should be able to use something like

    qtrans_getLanguage()=="fr"

    as the logic to show a widget when french is chosen and so on. though you may want to make that more robust as that will fail when qTranslate is inactive and your site will break a little. so use

    function_exists('qtrans_getLanguage') && qtrans_getLanguage()=="fr"

  3. luca_melis
    Member
    Posted 5 years ago #

    It worked just fine! Thanks a lot.

  4. alarch
    Member
    Posted 5 years ago #

    That was very helpful and helped me to display language-appropriate captions on Creative Clans slideshows (one English, one Welsh) using (for the English version of the slideshow):

    ( !is_home() && (function_exists('qtrans_getLanguage') && qtrans_getLanguage()=="en"))

    The !is_home prevents the slideshow displaying on the home page.

  5. Aces1
    Member
    Posted 5 years ago #

    Is there anything similar I can do for google translator?

    I'm trying to disable a WP E-commerce widget showing on pages translated from english when using the above plugin....

  6. alanft
    Member
    Posted 5 years ago #

    what you need to do there is check when the referring site matches "translate.google.com", so something like

    strpos( $_SERVER['HTTP_REFERER'], "translate.google.com")==false

    should mean that attempts to read your site referenced by that service will not see that widget.

    hope that helps

  7. Aces1
    Member
    Posted 5 years ago #

    sounds great, I'll give it a try... Thanks!

    Edit:

    It works the first time but if one clicks on a link on the page, the widget comes back and is translated....

    But that isn't the only issue with the translation plugin's operation, so i'm putting that idea on hold for the moment....

    Thanks again for your help.

Topic Closed

This topic has been closed to new replies.

About this Topic