1

I read a lot about what is the optimal to translate your website (french and english in my case)

I set up a Multi site where I created two site one french mywebsite.com/fr and one in english mywebsite.com/en

I am now in the process of translating my theme(in french by default) I added this to my theme function.php:

load_theme_textdomain('INTERluminaires', get_template_directory() . '/languages');

then modified my template files in order to be able to translate some text

<?php _e("Design et conseils", "INTERluminaires"); ?>

created a po and mo file with poedit, everything goes well.

I uploaded those files in my theme folder /languages

those files are named en_CA.po and en_CA.mo (I tried INTERluminaires-en_ca.po and mo to no avail)

when I change my theme language in settings general and refresh my website nothing is translated.

any idea what could be wrong here?

btw I managed to translate a plugin I installed without any problem.

1 Answer 1

3

You have incomplete code. You register your Theme's textdomain, but don't actually tell WordPress to load your translation files.

To this:

load_theme_textdomain('INTERluminaires', get_template_directory() . '/languages');

Add this:

$locale = get_locale();
$locale_file = get_template_directory() . "/languages/$locale.php";
if ( is_readable( $locale_file ) ) {
    require_once( $locale_file );
}

Or, altogether (and wrapped properly in a callback):

<?php
function wpse49326_translate_theme() {
    // Load Theme textdomain
    load_theme_textdomain('INTERluminaires', get_template_directory() . '/languages');

    // Include Theme text translation file
    $locale = get_locale();
    $locale_file = get_template_directory() . "/languages/$locale.php";
    if ( is_readable( $locale_file ) ) {
        require_once( $locale_file );
    }
}
add_action( 'after_setup_theme', 'wpse49326_translate_theme' );
?>
3
  • Thanks, in fact it works without it. but I'll add it to make sure I was so into my translation that I forgot to upload index.php (rookie mistake!) hence why it was not showing. Apr 18, 2012 at 18:19
  • 1
    Do you maybe know why Twenty Thirteen doesn't include the second part of this code (with get_locale() and require_once())?
    – Paul
    Jun 8, 2013 at 10:43
  • 1
    Chip, I realize this is an old question. Doesn't load_theme_textdomain() call load_textdomain() internally and then requires it by itself and merges it with the global array?
    – kaiser
    Sep 12, 2013 at 13:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.