0

I have a custom theme which is in Dutch and now i am trying to translate the theme into english. For this i am using poedit, and converted some theme strings into _e('string-is-here')

I save both en_US.po and en_US.mo into my-theme/languages and add this to functions.php

function theme_init(){
    load_theme_textdomain('my-theme', get_template_directory() . '/languages');
}
add_action ('init', 'theme_init');

to test it i edit wp-config.php by

define('WPLANG', 'en_US');

And i thought it was working, but when i changed WP_LANG back to

define('WPLANG', '');

The translated strings are always shown???

What am i overlooking?

regards

2

You are making wrong assumption here. define('WPLANG', ''); doesn't mean "original locale of the string" or anything like that, it is taken literally as "no locale specified".

And when it's nothing WP proceeds to assume default locale, which is en_US. This is why as soon as you add English translations of string they are displayed for this case.

So to test your original Dutch strings properly you need to set WPLANG to respective Dutch locale.

  • hmm i don't get it. Let me explain in the original theme there are Dutch string like "Gemaakt door", which i replaced with __('Gemaakt door', 'my-theme'). Now with poedit i translate the dutch strong to english "Made by" and saved the file as en_US.mo/en_US.po. Should i saved it asl nl_NL.mo? I am a bit confused as normally it's english translate too another language. regards – alex Oct 8 '14 at 11:36
  • When you have no locale WP thinks it is English. While you had no English translation — original strings where showing. But as soon as you added English translation — those are shown because locale is English. Now your original strings will only show for locales that don't have (or don't need) translation. – Rarst Oct 8 '14 at 11:47
  • i think i got it now. Do you know how i can set mydomain.com/en/ to set locale WP to use en_US? – alex Oct 8 '14 at 13:38
  • No idea. I tend to use language switcher plugin for testing. – Rarst Oct 8 '14 at 13:46
0

The load_theme_textdomain() function uses load_textdomain() internally. And that function offers a nice filter for debugging purposes (aside from altering the language:

$plugin_override = apply_filters( 'override_load_textdomain', false, $domain, $mofile );

Start debugging with a quick custom plugin and check if your file exists:

<?php
/** Plugin Name: Check if the themes MO file exists */
add_filter( 'override_load_textdomain', function( $override, $domain, $mofile )
{
    false !== strpos( $mofile, get_template_directory() ) AND var_dump(
        '=== CHECK LANGUAGE AND MO FILES ===',
        $mofile,
        file_exists( $mofile )
        'Current locale: '.get_locale(),
        'Available languages: ',
        get_available_languages(),
    );
    return false;
}, 10, 3 );

Note that this will show you only parent theme MO files. If you have a child theme in use, you better go with get_stylesheet_directory() both in your code as well as in above debug plugin code.

To check your current locale, you can dump get_locale(). To see all available languages, dump get_available_languages(). Those are the last two dumps in above plugin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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