Replace word's in translation


Если необходимо заменить какое-то из слов или фраз внутри файла перевода .pot - можно воспользоваться следующей функцией

function my_text_strings( $translated_text, $text, $domain ) {
	switch ( $translated_text ) {
		case 'Sale!' :
			$translated_text = __( 'Clearance!', 'woocommerce' );
			break;
		case 'Add to cart' :
			$translated_text = __( 'Add to basket', 'woocommerce' );
			break;
		case 'Related Products' :
			$translated_text = __( 'Check out these related products', 'woocommerce' );
			break;
	}
	return $translated_text;
}
add_filter( 'gettext', 'my_text_strings', 20, 3 );

источник

или вот такой функцией

Edit the $words array. Add the words you want to replace to the keys and the replacement text to the keys’ values.

add_filter(  'gettext',  'wps_translate_words_array'  );
add_filter(  'ngettext',  'wps_translate_words_array'  );
function wps_translate_words_array( $translated ) {
 
     $words = array(
            // 'word to translate' = > 'translation'
            'Posts' => 'Article',
            'Post' => 'Articles',
            'Pages' => 'Stuffing',
            'Media' => 'Upload Images',
            'Links' => 'Blog Roll',
            );
 
     $translated = str_ireplace(  array_keys($words),  $words,  $translated );
     return $translated;
}

источник

ПОЛЕЗНО  WooCommerce – How to Show a Confirm Message before Removing an Item from the cart / Update Basket on Quantity Change