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.

Read More

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">
<h1>Latest News</h1>
...

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

Related posts

4 comments

  1. 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<!--:-->'); ?>
    
  2. This solution worked for me

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

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

  3. 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! 🙂

Comments are closed.