0

I used 3th party plugin in my theme but some of them don't have my target language support.I want to add new language support to these plugins from my theme plugin.How can I do it?

1 Answer 1

0

If discussed plugin already uses load_plugin_textdomain() function to load its translations, usually it is enough to place <plugin_name>-<locale_code>.mo file to the wp-content/languages/plugins directory. If it doesn't (or you can't do it for some reason), you can use init hook to load its translation via your functions.php. Here is an example from one of my child themes:

function load_plugin_translations() {
    if ( is_plugin_active( 'woocommerce-payment-status/woocommerce-payment-status.php' ) ) {
        load_textdomain( 'woocommerce_payment_status', get_stylesheet_directory() . '/languages/woocommerce_payment_status-' . get_user_locale() . '.mo' );
    }
}
add_action( 'init', 'load_plugin_translations' );

Here I use woocommerce_payment_status-<locale>.mo translation file from the languages folder under my child theme. Replace woocommerce-payment-status/woocommerce-payment-status.php plugin ID and woocommerce_payment_status textdomain ID according to your plugin.

Your Answer

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

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