1
votes

I have plugins .mo translations files in the wp-content/languages/plugins folder, I would like to add my custom translation for a specific plugin and put the .mo file into the wp-content/themes/my_theme folder, so the new .mo file which in the theme folder overrides the original .mo which in the plugins languages folder.

Solved: translation upgrade safe:

add_filter( 'load_textdomain_mofile', 'load_custom_plugin_translation_file', 10, 2 );

/*
 * Replace 'textdomain' with your plugin's textdomain. e.g. 'woocommerce'. 
 * File to be named, for example, yourtranslationfile-en_GB.mo
 * File to be placed, for example, wp-content/lanaguages/textdomain/yourtranslationfile-en_GB.mo
 */
function load_custom_plugin_translation_file( $mofile, $domain ) {
  if ( 'woocommerce' === $domain ) {
    $mofile = get_stylesheet_directory() . '/languages/woocommerce-' . get_locale() . '.mo';
  }
  return $mofile;
}
1

1 Answers

1
votes

Solved: translation upgrade safe

add_filter( 'load_textdomain_mofile', 'load_custom_plugin_translation_file', 10, 2 );

/*
 * Replace 'textdomain' with your plugin's textdomain. e.g. 'woocommerce'. 
 * File to be named, for example, yourtranslationfile-en_GB.mo
 * File to be placed, for example, wp-content/lanaguages/textdomain/yourtranslationfile-en_GB.mo
 */
function load_custom_plugin_translation_file( $mofile, $domain ) {
  if ( 'woocommerce' === $domain ) {
    $mofile = get_stylesheet_directory() . '/languages/woocommerce-' . get_locale() . '.mo';
  }
  return $mofile;
}