WordPress theme .mo-file won’t load

I am developing a theme that implements multiple languages. I have a few strings that will have to be translated in the theme itself. I would like to use a .po and .mo file. For some reason, when I try to load the files, they don’t load properly and I have no idea why.

I have tried using the following code to load the correct text domain.

Read More
function my_theme_localized($locale)
{
    if (isset($_GET['lang'])){
        return sanitize_key($_GET['lang']);
    }

    return $locale;
}
add_filter('locale', 'my_theme_localized');

function my_theme_setup(){
    load_theme_textdomain('theme', TRANSLATION_URL);
}
add_action('after_setup_theme', 'my_theme_setup');

I debugged a bit and the link to the mo-file that is generated in the class-wp-theme should be correct. The locale I am using is returned properly and the corresponding files are in the directory (pl_PL.mo for example).

I have tried everything that I can think of and I still don’t know what is wrong with this piece of code. Anyone who can help me?

Related posts

1 comment

  1. Solved the problem. I used the link to my textdomain, instead of the absolute path on my server. So the problem was situated in my TRANSLATION_URL-variable.

    You should use something like this:

    define("THEME_URL", get_template_directory());
    define("TRANSLATION_URL", THEME_URL . "/languages");
    

Comments are closed.