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">
<h1>Latest News</h1>
...
I would like to translate the content inside the <section>
and <h1>
tag for example in french.
4 Answers
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<!--:-->'); ?>