How to translate content in category.php or index.php with qtranslate?

I was wondering how to translate content under index.php (or category.php with qtranslate?).

I'm using twenty twelve theme.

My code on index.php:

?php
/**
* The main template file.
* @package WordPress
* @subpackage Twenty_Twelve
* @since Twenty Twelve 1.0
*/
?
?php get_header(); ?
?php 
$page_id = 1500;
$page_data = get_page( $page_id );
echo apply_filters('the_content', $page_data-post_content);
?
section id="last-articles_homepage"
h1Latest News/h1
...

I would like to translate the content inside the section and h1 tag for example in french.

Topic plugin-qtranslate Wordpress

Category Web


I got this from WP Forums and it worked for me.

<?php _e("[:fr]Les réseaux sociaux[:en]Social Media[:]"); ?>

This solution worked for me

<?php echo __('[:fr]Plus[:en]More'); ?>

Note : the " : " is before the language, not after


I found the solution for a related problem of mine in a Qtranslate Support forums:

<?php if(qtrans_getLanguage() == "fr") : ?> <h1>This is French</h1>
<?php endif ?> 
<?php if(qtrans_getLanguage() == "en") : ?> <h1>This is English</h1> 
<?php endif ?>

I hope it would work for you! :)


Most correct way to do this would be to use WordPress translations.

You should replace this static text with:

<?php _e('YOUR TEXT', 'your_text_domain'); ?>

And add text domain to your theme.

More on this topic: http://codex.wordpress.org/I18n_for_WordPress_Developers

You can also...

... use qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage function.

Just use it like so:

<?php echo qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage('<!--en:-->Latest News<!--:--><!--fr:-->dernières Nouvelles<!--:-->'); ?>

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.