Wordpress:如何通过主题文件夹覆盖插件翻译?

时间:2018-11-22 22:25:58

标签: wordpress woocommerce

我在.mo文件夹中有插件wp-content/languages/plugins翻译文件,我想为特定插件添加自定义翻译,并将.mo文件放入wp-content/themes/my_theme文件夹,因此主题文件夹中的新.mo文件将覆盖插件语言文件夹中的原始.mo文件。

已解决: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 个答案:

答案 0 :(得分:0)

已解决: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;
}