Wordpress: Как переопределить перевод плагина через папку темы? - PullRequest
0 голосов
/ 23 ноября 2018

У меня есть плагины .mo файлы переводов в папке wp-content/languages/plugins, я хотел бы добавить свой собственный перевод для определенного плагина и поместить файл .mo в папку wp-content/themes/my_theme, поэтому новый .moфайл, который в папке темы заменяет исходный .mo, который находится в папке языков плагинов.

решено: безопасное обновление перевода :

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 голосов
/ 23 ноября 2018

Решено: Обновление перевода безопасно

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;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...