DW Question Answer 的问题测试:
bbPress 的帖子测试:
BuddyPress 和 WooCommerce 就没有什么测试的必要了。
代码如下,添加到当前主题的 functions.php 文件即可:
- 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 );