У меня есть плагины .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;
}