How to reload wordpress textdomains at runtime

I’m currently using this to reload my theme and plugin textdomain in order to send e-mails (admin move, in admin language) in the user language.

add_filter("theme_locale", array($this, "theme_locale"), 9999, 2);
add_filter("plugin_locale", array($this, "plugin_locale"), 9999, 2);
$this->load_textdomains();
remove_filter("theme_locale", array($this, "theme_locale"), 9999, 2);
remove_filter("plugin_locale", array($this, "plugin_locale"), 9999, 2);


public function load_textdomains() {
    if (function_exists("WC")) {
        WC()->load_plugin_textdomain();
    }
    if (class_exists("My_Plugin_Class")) {
        My_Plugin_Class::load_plugin_textdomain();
    }
    load_my_theme_textdomain();
}

And the theme/plugin functions works like this:

function load_my_theme_textdomain(){
    unload_textdomain('my-theme-textdomain');
    load_theme_textdomain('my-theme-textdomain', get_template_directory() . '/i18n/');
}

And thats okay, works fine.
But in my e-mail, i translate things using WORDPRESS textdomain.

How can i reload wordpress default textdomain, at runtime, like this?
The one that is used when using __ function without domain parameter.

0

Leave a Comment