[closed] qtranslate - How to add language switcher button in menu bar (35 posts)

  1. acub
    Posted 2 years ago #

    @BigMacOnTrack: The function you're looking for is qtrans_generateLanguageSelectCode($type), where $type can have any of these values: image|text|both|dropdown. "both" means flag+text. Depending on $type, this will either generate an unordered list with the flags or a dropdown (options/select).

    Now all you need to do is place this into your pages, where you want it, using a WP or theme hook. You can use any hook you want, just make sure it is called in your theme on the pages you want the language chooser displayed. For example, if you want the selector to be the first thing rendered to your page, you can use get_header as your action hook, adding this code to your functions.php (preferably in your child theme):

    add_action('get_header', 'add_my_language_chooser');
    function add_my_language_chooser() {
    	if (function_exists('qtrans_generateLanguageSelectCode')) qtrans_generateLanguageSelectCode('both');

    As you might notice, this only outputs the selector if qtranslate is present and activated (so the function exists). If it doesn't, nothing happens.

    So the above code will output something similar to:

    <ul class="qtrans_language_chooser" id="qtranslate-chooser">
    	<li class="active">
    		<a href="http://test.websiter.ro/blog/" class="qtrans_flag_ro qtrans_flag_and_text" title="Română"><span>Română</span></a></li>
    		<a href="http://test.websiter.ro/blog/?lang=en" class="qtrans_flag_en qtrans_flag_and_text" title="English"><span>English</span></a></li>

    , depending on the languages you have installed. Feel free to use the classes and ids from that code to style up the look of your language chooser. For example, if you want to hide the active language from the selector, use

    #qtranslate-chooser .active {display: none;}

    Good luck.

  2. JanetSlinkard
    Posted 2 years ago #

    I'm having a bit of trouble with Solution #2: When creating the menu items, I don't want to (or know how to) create pages within sub-directories such as "/en/"for english, "/fr/" for French, etc. I have added my translated content within tags on each page. I am VERY new to WordPress...any suggestions?
    My site url is:

  3. Tim Morley
    Posted 2 years ago #

    Hi Janet.

    If you're new to WordPress and to qTranslate, you probably don't want or need to delve into tweaks like the ones in this thread.

    There is a language chooser included with qTranslate, as a widget. From the WP dashboard, choose Appearance —> Widgets, and drag the "qTranslate Language Choose" from the left side into one of the "widget areas" on the right. You should then see the language chooser appear on your website.

    As for creating separate subdirectories with the content in different languages — you don't have to. With qTranslate installed, any time you edit a Post or a Page, you can do so in as many languages as you have enabled in qTranslate. You just create the content within WP/qTranslate, and it Just Works™.

    If it's not working for you, can you describe what you expected to happen, and what is actually happening.

  4. loretosonoio
    Posted 1 year ago #

    Hi, i've try the second solution and it work fine. I've a little problem with default language...
    The second item change the code for language. I wrote /en/ and wordpress change automatically in default language (/it/)
    Can you help me? I'm going crazy!!

  5. Andrew Nevins
    Forum moderator
    Posted 1 year ago #

    You can create a new thread here: http://wordpress.org/support/theme/customizr#postform

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic