qTranslate

Installation

Download, install and activate qTranslate.

Go to Settings / Languages. On the bottom right part of the page, disable and enable the desired languages.

Press show next to Advanced Settings to unfold them. In the URL Modification Mode, select Use Pre-Path Mode (Default, puts /en/ in front of URL) and press Save Changes.

Download, install and activate qTranslate slug.

Go to Settings / Permaling Settings. Select Post Name and press Save Changes.

Go to Appearance / Widgets. Add Language Selector to the desired position.

How to insert a language that does not appear on the list

If your language does not appear in the list, for example Greek, then:

  1. In the Language Code, add the 2 letter ISO code for your language, for greek ‘el’.
  2. Select your flag.
  3. Enter the Name of the language, which will be displayed on the site, eg. Greek.
  4. Enter the PHP and WordPress Locale for the language, eg. el_GR.
  5. Add a not available message.
  6. Press Add language button.
  7. Enable the language from the table.

How to align horizontally the flags or titles

Add this in your css:

.qtrans_language_chooser li { 
    float:left; 
    margin: 0 0 0 5px; 
}

Useful functions

Use qtrans_generateLanguageSelectCode to echo the menu without using a widget

echo qtrans_generateLanguageSelectCode('text');
echo qtrans_generateLanguageSelectCode('image');
echo qtrans_generateLanguageSelectCode('both');

User qtrans_getLanguage() to get the current langage. Eg.

echo qtrans_getLanguage(); // returns 'en'

Use __(string $str) to translate a string, eg. (you will have to echo it)

echo __(the_title());

Use _e(string $str) to translate a string, eg. (you don’t have to echo it)

echo _e(the_title());

Use qtrans_convertURL(string $str) to tranlate a url address, eg.

echo qtrans_convertURL(get_option('home'));

Error with search

To fix this error, read this article.

Error with custom nav menus

To fix this problem, open appearance / menu, create your custom menu item, and in the navigation label enter something like this

<!--:el-->My menu label in greek<!--:--><!--:en-->My menu label in english<!--:-->

Or

  1. Oopen your phpMyAdmin to manage the DB.
  2. Go to table wp_posts and click on the Search link.
  3. Filter by post_type=nav_menu_item
  4. Look for the non translated records (field post_title)
  5. Modify the field as shown above.

My links are messed up

Try adding this line in functions.php

add_filter('post_type_link', 'qtrans_convertURL');

Make it SEO friendly

Make your site title SEO friendly

Since qTranslate plugin introduced its new feature about QuickTags, now we can translate our field content to another languages so easily. Simply add this language tag [:en] for English translation at the beginning of your English field content, and also add another language tag at the beginning of your field content that contains of the words or sentences in your language.

Go to your admin panel, then click on Settings -> General

At the Blog Title directive, add the language tag.

[:en]My First Website[:id]Situs Pertamaku

How to add a separator between languages

Add the following code in your functions:

// add separator
function qtrans_generate_language_list($sep = " | ") {
    global $q_config;
    $languages = qtrans_getSortedLanguages();
    $num_langs = count($languages);
    $id = 'qtranslate-chooser';
    $url = is_404() ? get_option('home') : '';

    echo '<ul id="' . $id . '">';
    foreach ($languages as $language) {
        $classes = array('lang-' . $language);
        if ($language == $q_config['language'])
            $classes[] = 'active';

        echo '<li><a href="' . qtrans_convertURL($url, $language) . '"';
        echo ' hreflang="' . $language . '" title="' . $q_config['language_name'][$language] . '"';
        echo '>' . $q_config['language_name'][$language] . '</a>';
        if (--$num_langs > 0) {
            echo '<span>' . $sep . '</span>';
        }
        echo '</li>';
    }
    echo "</ul>";
}

Then, instead of

echo qtrans_generateLanguageSelectCode('text')

use

echo qtrans_generate_language_list();

How to fix “The qTranslate Editor has disabled itself because it hasn’t been tested with your WordPress version yet” error

If you have WordPress auto-updates on, then after a wordpress update, the qtranslate may become incompatible with the newly update version of WordPress. That sucks. To fix it permanently (without worrying for future updates) use the steps below. Just remember, that if you make the changes, and then update the qtranslate plugin, you will lose the changes below and you’ ll have to remake them.

  1. Go to plugins and press ‘edit’ in qtranslate.
  2. In your qtranslate.php file, change the line below.
define('QT_SUPPORTED_WP_VERSION', get_bloginfo('version'));

If TinyMCE Advanced plugin does not show

Then, If you open your firebug javascript console you probably have the error below:

Deprecated TinyMCE API call: <target>.onSaveContent.add(..)

To fix this open qtranslate_javascript.php and change the line 292:

// ed = new tinymce.Editor(id, tinyMCEPreInit.mceInit[id]); // change this line
ed = new tinymce.Editor(id, tinyMCEPreInit.mceInit[id], tinymce); // to this

How to fix the error PHP Catchable fatal error

If qtranslate returns this error:

PHP Catchable fatal error: Object of class WP_Post could not be converted to string in ../wp-content/plugins/qtranslate/qtranslate_core.php on line 455

Then change the next 2 lines in qtranslate_core.php in line 458

function qtrans_dateFromPostForCurrentLanguage($old_date, $format ='') {
    global $post;
    return qtrans_strftime(qtrans_convertDateFormat($format), mysql2date('U',$post->post_date), $old_date);
}

 

Post A Comment

Anti-Spam Quiz: