Force Plugin to English Translation

Here’s my thing:

I’m using a plugin that has multilang capabilities. The point is that the language translation in my country lang is very bad and it makes more complex than simpler my work. :D.
So is there a way to force a plugin to not to use multilanguage and be showed, at least, in English?

Related posts

Leave a Reply

2 comments

  1. What’s the plugin? Is it using custom translations in mo/po files? Is there an admin interface which allows you to set the plugin locale?

    There is a generic filter which you might be able to add to the plugin code to set the language which might look something like the following (obviously set the language to what you want:

    add_filter('locale', 'wpse_get_locale');
    
    // returns the locale based on user preference
    function wpse_get_locale($locale) {
    // get_current_user_id uses wp_get_current_user which may not be available the first time(s) get_locale is called
        if (function_exists('wp_get_current_user'))
            $loc = get_user_meta(get_current_user_id(), 'user_lang', 'true');
        return isset($loc) && $loc ? $loc : $locale;
    }
    

    However I wonder if it might not be easier to improve the translation of the plugin by editing the mo/po files or whatever they use for the string translation?

  2. // to force use English, this filter value must return true.
    add_filter('override_load_textdomain', 'myPlugin_OverrideLoadTextDomain', 10, 3);
    
    add_filter('plugin_locale', 'myPlugin_forceUseLanguageForCertainPlugin', 10, 2);
    
    function myPlugin_OverrideLoadTextDomain($override, $domain, $mofile) 
    {
        if ($domain === 'woocommerce') // change text domain from woocommerce to what you want.
        {
            $override = true;
        }
    
        return $override;
    }
    
    function myPlugin_forceUseLanguageForCertainPlugin($locale, $domain) 
    {
        if ($domain === 'woocommerce') // change text domain from woocommerce to what you want.
        {
            $locale = 'en_US';// change your locale here to whatever you want.
        }
    
        return $locale;
    }
    

    It required 2 filter hooks to work.