Last update at :2024-07-07,Edit by888u
Using Baidu Translation's translation API to automatically translate Chinese article titles into English. After testing, it is suitable for WordPress built-in article types and custom article types added by plug-ins such as bbPress, BuddyPress, WooCommerce, and DW Question Answer.
The code is as follows, just add it to the functions.php file of the current theme:
function translate_chinese_post_title_to_en_for_slug( $title ) { /* transtype: trans realtime */ $translation_render = 'http://fanyi.baidu.com/v2transapi?from=zh&to=en&transtype=realtime&simple_means_flag=3&query='.$title; $wp_http_get = wp_safe_remote_get( $translation_render ); if ( empty( $wp_http_get->errors ) ) { if ( ! empty( $wp_http_get['body'] ) ) { $trans_result = json_decode( $wp_http_get['body'], true ); $trans_title = $trans_result['trans_result']['data'][0]['dst']; return $trans_title; } } return $title; } add_filter( 'sanitize_title', 'translate_chinese_post_title_to_en_for_slug', 1 );
Reprinted from: https://jiub.ren/2923.html
Recommended site search: Hong Kong host, domain name registration official website, American and European cloud servers, registered domain names, all-purpose virtual hosts, space registration, Hong Kong cloud servers, free server website ip search, ip proxy server,
发表评论