qTranslate – show articles in two languages [closed]

If you go by that route, you might easily break any other plugin that does stuff with the post content, like custom galleries, excerpt plugins, and such.
I think there is a less destructive way to achieve what you (we) want.

When a post is about to be displayed, the function qtrans_useCurrentLanguageIfNotFoundShowAvailable is called by qTranslate, attached as a filter on the the_content hook.

Since wordpress themes are executed after plugins (I assume you are writing a theme and not a plugin), you can replace that hook with one of your own, outputting the languages you want.

You can do something like this (in your functions.php file)

// Remove qTranslate default display hook.
// If this code breaks, update the parameters according to
// the qtranslate_hooks.php file of the plugin.
remove_filter('the_content', 'qtrans_useCurrentLanguageIfNotFoundShowAvailable', 0);

// Add a custom filter for the content
add_filter('the_content', 'qtrans_useLanguagesIDecide', 0);
function qtrans_useLanguagesIDecide($content) {
  $YOUR_LANGUAGES = array('en', 'fr');
  $output="";
  foreach($YOUR_LANGUAGES as $language)
    $output .=
        '<div class="language-'.$language.'">'.
          qtrans_use($language, $content, true).
        '</div>';
  return $output;
}

Note also that there are other hooks you might like to similarly override, like the_excerpt or the_content_rss.

If your blog might not have all the languages for every post (like mine), you might also want to improve your filter, to avoid that the message “Sorry, this entry is only available in Française” in place of the occasional missing english translation:

function qtrans_useLanguagesIDecide($content) {
  $YOUR_LANGUAGES = array('en', 'fr');

  $show_languages = $YOUR_LANGUAGES;
  $qtranslate_languages = qtrans_split($content); // take a peek at translated content
  foreach($show_languages as $key => $language) {
    $translated_content = isset($qtranslate_languages[$language]) ? trim($qtranslate_languages[$language]) : '';
    if(empty($translated_content))
      // remove missing language
      unset($show_languages[$key]);
  }

  $output="";
  foreach($show_languages as $language)
    $output .=
        '<div class="language-'.$language.'">'.
          qtrans_use($language, $content, true).
        '</div>';
  return $output;
}

In this case, don’t be tempted to use $translated_content directly, as qTranslate does its job better than us.