Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Translating footer with qtranslate-x WordPress

Hi,

I have managed to translate the whole website in four languages but somehow I can't make the footer work. It switches randomly between one of the four languages or get stuck and only show the same one.

To do so I have an option in theme option where I can customize the footer, the excerpt etc.

I added this to it:

[:en] &copy; [site-link] <strong>[email protected]</strong> The first Montessori center in Barcelona since 1924. [:es] &copy; [the-year] [site-link] <strong>[email protected]</strong> El primero centro Montessori a Barcelona desde 1924. [:ca] &copy; [site-link] <strong>[email protected]</strong> El primer centre Montessori a Barcelona des de 1924. [:fr] &copy; [site-link] <strong>[email protected]</strong> Le premier centre Montessori à Barcelone depuis 1924.

it works for a while and then stops working. I also tried this:

&copy; [site-link] <strong>[email protected]</strong> [:en]The first Montessori center in Barcelona since 1924.[:es]El primero centro Montessori a Barcelona desde 1924.[:ca]El primer centre Montessori a Barcelona des de 1924.[:fr]Le premier centre Montessori à Barcelone depuis 1924.

No success.

I tried to add this into the footer.php:

<?php if( qtrans_getLanguage() == 'en' ){ ?>
<!-- &copy; [site-link] <strong>[email protected]</strong> The first Montessori center in Barcelona since 1924. -->
<?php if( qtrans_getLanguage() == 'fr' ){ ?>
<!-- &copy; [site-link] <strong>[email protected]</strong> Le premier centre Montessori à Barcelone depuis 1924. -->
<?php if( qtrans_getLanguage() == 'es' ){ ?>
<!-- &copy; [the-year] [site-link] <strong>[email protected]</strong> El primero centro Montessori a Barcelona desde 1924. -->
<?php if( qtrans_getLanguage() == 'ca' ){ ?>
<!-- &copy; [site-link] <strong>[email protected]</strong> El primer centre Montessori a Barcelona des de 1924. -->
<?php } ?>


It's not working either for me. I'm pretty sure there is something easy to do but I just can't figured it out, what about you guys?

Thanks!

Answers (2)

2015-06-16

Francisco Javier Carazo Gil answers:

In this case I would use jQuery:

add_action( "wp_footer", "translate_footer" );

function translate_footer(){
?>
<script>
jQuery( document ).ready( function( $ ){
<?php if( qtrans_getLanguage() == 'en' ){ ?>
$( "#id_footer").html("<!-- &copy; [site-link] [email protected] The first Montessori center in Barcelona since 1924. -->");
<?php if( qtrans_getLanguage() == 'fr' ){ ?>
<!-- &copy; [site-link] [email protected] Le premier centre Montessori à Barcelone depuis 1924. -->
<?php if( qtrans_getLanguage() == 'es' ){ ?>
<!-- &copy; [the-year] [site-link] [email protected] El primero centro Montessori a Barcelona desde 1924. -->
<?php if( qtrans_getLanguage() == 'ca' ){ ?>
<!-- &copy; [site-link] [email protected] El primer centre Montessori a Barcelona des de 1924. -->
<?php } ?>
});
</script>
<?php
}


And the same for every language:

$( "#id_footer").html("<!-- &copy; [site-link] [email protected] The first Montessori center in Barcelona since 1924. -->");


artaudlemomo comments:

thanks for you help, I tried to add the code you gave me into the footer.php but it's not working, the footer disappear.

2015-06-16

MJ answers:

Not sure JQuery is the best place to do site translations even if it's possible. I'd try to work it out with the plugin so your translations don't end up all over the shop and difficult to maintain. Might it be a caching issue? Do you have a caching plugin installed that needs clearing?

Your Spanish translation btw, should be: "El primer centro Montessori en Barcelona desde 1924"


artaudlemomo comments:

thanks i will change the translation!

I have cache plugin that i used regulary. what I don't understand is that the rest of the website works fine, only the footer bugs.


MJ comments:

I've looked at the docs. Try this version:

&copy; [site-link] [email protected] [:en] The first Montessori center in Barcelona since 1924. [:][:es] El primero centro Montessori a Barcelona desde 1924. [:]

See if it works for those 2 languages.


artaudlemomo comments:

I just did like you told me, it's not working :(


MJ comments:

According to the docs it should work. Perhaps your theme isn't interpreting the shorcodes.

Try the PHP in your footer again. Remove the HTML comments and echo the strings, like:


<?php
if( qtrans_getLanguage() == 'en' ){
echo '&copy; [site-link] [email protected] The first Montessori center in Barcelona since 1924. ';
} else if( qtrans_getLanguage() == 'fr' ){
echo '&copy; [site-link] [email protected] Le premier centre Montessori à Barcelone depuis 1924. ';
}
?>


artaudlemomo comments:

this is my footer, where shall I put it?: thanks!

<?php
/**
* Displays the footer section of the theme.
*
* @package Theme Horse
* @subpackage Clean_Retina_Pro
* @since Clean Retina Pro 1.0
*/
?>

</div><!-- #main -->

<?php
/**
* cleanretina_after_main hook
*/
do_action( 'cleanretina_after_main' );
?>

<?php

/**
* cleanretina_before_footer hook
*/
do_action( 'cleanretina_before_footer' );
?>

<footer id="colophon" class="clearfix">
<?php
/**
* cleanretina_footer hook
*
* HOOKED_FUNCTION_NAME PRIORITY
*
* cleanretina_open_wrapper_div 5
* cleanretina_footer_widget_area 10
* cleanretina_open_sitegenerator_div 15
* cleanretina_socialnetworks 20
* cleanretina_footer_info 25
* cleanretina_close_sitegenerator_div 30
* cleanretina_close_wrapper_div 35
* cleanretina_backtotop_html 40
*/
do_action( 'cleanretina_footer' );
?>
</footer>

<?php
/**
* cleanretina_after_footer hook
*/
do_action( 'cleanretina_after_footer' );
?>

<?php
/**
* cleanretina_after hook
*/
do_action( 'cleanretina_after' );
?>
<?php if (!is_front_page()){ ?>
<script>
jQuery(function(){
jQuery(window).scroll(function(){
if(jQuery(window).scrollTop()>=100){
jQuery("#main").addClass("main_info");
}
else {
jQuery("#main").removeClass("main_info");
}
});
});
</script>
<?php } ?>

<script>
jQuery(function(){
jQuery(window).scroll(function(){
if(jQuery(window).scrollTop()>=250){
jQuery(".back-to-top").show();
}
else {
jQuery(".back-to-top").hide();
}
});
});


</script>






<script src="<?php //bloginfo( 'template_directory' ); ?>/nidoassets/js/jquery.min.js"></script>
<script src="<?php bloginfo( 'template_directory' ); ?>/nidoassets/js/modernizr.custom.js"></script>
<script src="<?php bloginfo( 'template_directory' ); ?>/nidoassets/js/script.js"></script>
<script>
jQuery(function() {
cbpBGSlideshow.init();
});
</script>
<script src="<?php bloginfo( 'template_directory' ); ?>/nidoassets/js/jquery.imagesloaded.min.js"></script>
<script src="<?php bloginfo( 'template_directory' ); ?>/nidoassets/js/cbpBGSlideshow.min.js"></script>
</body>
</html>


MJ comments:

Just to test it you can put it right after <footer id="colophon" class="clearfix">

But the right place is functions.php, where you should hook it to wp_footer, or perhaps in your case cleanretina_footer. But test it first.


MJ comments:

So, in functions.php:


add_action( "cleanretina_footer", "translate_footer" );

function translate_footer(){

if( qtrans_getLanguage() == 'en' ){

echo '&copy; [site-link] [email protected] The first Montessori center in Barcelona since 1924. ';

} else if( qtrans_getLanguage() == 'fr' ){

echo '&copy; [site-link] [email protected] Le premier centre Montessori à Barcelone depuis 1924. ';

}

}


The ideal solution is to work out why it's not picking up the shortcodes in your theme, because it looks like your theme does support them in the footer options. But I think the above should work.


artaudlemomo comments:

Ok I have added the code you sent me. It's working now but the theme now displays [site-link] [email protected] The first Montessori center in Barcelona since 1924.

instead of displaying the site link, basically the [site-link] short code appear on the front end.

This is the address by the way: www.nidobcn.com


thanks for your help!


MJ comments:

Good, I wanted to make sure the translations were working first.

You now need to pass the shortcode through the WordPress do_shortcode function. Something like this for each translation/shortcode:

echo '&copy; ' . do_shortcode('[site-link]') . '[email protected] The first Montessori center in Barcelona since 1924. ';

Let me know if that's not clear.


artaudlemomo comments:

Hi MJ,

Thanks a lot it did work in the end.


The only left issue is that my footer isn't aligned with the language switcher I have of the right of it.

you can see it here: www.nidobcn.com


thanks!


artaudlemomo comments:

Oh I just saw something, on mobile phone now the footer is above the language switcher instead of below and isn't centered.


MJ comments:

OK, change one bit of the code. Instead of add_action( "cleanretina_footer", "translate_footer" ); make it add_action( "cleanretina_after", "translate_footer" );


I'm getting those values from the PHP file you provided. If the above doesn't work, try one of the other hooks. The trick is to find the hook that your theme uses to print the footer.

There may be some CSS to add. I'll look at that later but let me know if the above works.


MJ comments:

Having said that, cleanretina_footer look like the right place though. Let me know how you get on.


artaudlemomo comments:

Hi MJ,

Thanks for the reply.

I have change accordingly but it isn't working as you can see in the screen shot.

I don't understand how I can try "the other hooks" though.