fix: wpai_meta_description translate
This commit is contained in:
@@ -228,11 +228,16 @@ class WPT_Content_Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function translate_wordpress_ai_meta_description_metadata( $value, $post_id, $meta_key, $single ) {
|
public function translate_wordpress_ai_meta_description_metadata( $value, $post_id, $meta_key, $single ) {
|
||||||
if ( 'wpai_meta_description' !== $meta_key || ! $single || ! is_string( $value ) ) {
|
if ( 'wpai_meta_description' !== $meta_key || ! $single ) {
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->translated_value( $value, 'post:' . $post_id . ':meta:wpai_meta_description' );
|
$source_value = is_string( $value ) ? $value : get_metadata_raw( 'post', $post_id, $meta_key, true );
|
||||||
|
if ( ! is_string( $source_value ) ) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->translated_value( $source_value, 'post:' . $post_id . ':meta:wpai_meta_description' );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function translate_term_object( $term, $taxonomy, $context = '' ) {
|
public function translate_term_object( $term, $taxonomy, $context = '' ) {
|
||||||
|
|||||||
@@ -22,12 +22,14 @@ class DocumentTitleTest extends TestCase {
|
|||||||
$identity_key = WPT_Translation_Identity::key( $description, 'zh', 'en', 'post:42:meta:wpai_meta_description', 'baidu-vip-v1' );
|
$identity_key = WPT_Translation_Identity::key( $description, 'zh', 'en', 'post:42:meta:wpai_meta_description', 'baidu-vip-v1' );
|
||||||
$store->values[ $identity_key ] = array( 'translated_value' => 'Translated description' );
|
$store->values[ $identity_key ] = array( 'translated_value' => 'Translated description' );
|
||||||
$controller = new WPT_Content_Controller( $store, new WPT_Test_Language_Router() );
|
$controller = new WPT_Content_Controller( $store, new WPT_Test_Language_Router() );
|
||||||
|
global $wpt_test_post_meta;
|
||||||
|
$wpt_test_post_meta[42]['wpai_meta_description'] = $description;
|
||||||
|
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'Translated description',
|
'Translated description',
|
||||||
$controller->translate_wordpress_ai_meta_description_metadata( $description, 42, 'wpai_meta_description', true )
|
$controller->translate_wordpress_ai_meta_description_metadata( null, 42, 'wpai_meta_description', true )
|
||||||
);
|
);
|
||||||
$this->assertNull( $controller->translate_wordpress_ai_meta_description_metadata( null, 42, 'wpai_meta_description', true ) );
|
$this->assertNull( $controller->translate_wordpress_ai_meta_description_metadata( null, 42, 'wpai_meta_description', false ) );
|
||||||
$this->assertSame( $description, $controller->translate_wordpress_ai_meta_description_metadata( $description, 42, '_unrelated_meta', true ) );
|
$this->assertSame( $description, $controller->translate_wordpress_ai_meta_description_metadata( $description, 42, '_unrelated_meta', true ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,6 +14,14 @@ function wp_parse_args( $args, $defaults = array() ) {
|
|||||||
return array_merge( $defaults, $args );
|
return array_merge( $defaults, $args );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_metadata_raw( $meta_type, $object_id, $meta_key = '', $single = false ) {
|
||||||
|
global $wpt_test_post_meta;
|
||||||
|
|
||||||
|
$value = $wpt_test_post_meta[ $object_id ][ $meta_key ] ?? null;
|
||||||
|
|
||||||
|
return $single ? $value : array( $value );
|
||||||
|
}
|
||||||
|
|
||||||
require_once dirname( __DIR__ ) . '/includes/interface-wpt-translation-provider.php';
|
require_once dirname( __DIR__ ) . '/includes/interface-wpt-translation-provider.php';
|
||||||
require_once dirname( __DIR__ ) . '/includes/class-wpt-translation-result.php';
|
require_once dirname( __DIR__ ) . '/includes/class-wpt-translation-result.php';
|
||||||
require_once dirname( __DIR__ ) . '/includes/class-wpt-translation-identity.php';
|
require_once dirname( __DIR__ ) . '/includes/class-wpt-translation-identity.php';
|
||||||
|
|||||||
Reference in New Issue
Block a user