What should I do if the WP Slug Translate plugin fails?Add code to translate article alias to English

Chen Weiliang: What should I do if the WP Slug Translate plugin fails?

Add code to translate article alias to English

Due to manyInternet marketingFor practitionerswordpress websitedoWeb Promotion, in order to solve the problem of "automatically translate Chinese aliases into English aliases", many of them install the WP Slug Translate plugin.

However, now the website of the author of the WP Slug Translate plugin has been closed, indicating that the other party has given up maintaining this plugin.

In other words, everything developed by the other sideWordPress pluginhas expired...

However, we can use Baidu Translate's API to automatically translate WordPress Chinese article titles into English.

Add automatic translation of code

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 );

Chen WeiliangAfter testing, if you add the above code for Baidu's automatic translation of wordpress article aliases, after clicking "Publish", "Timer" or "Update" in the article editor, the loading time will be much slower than if this code is not added, and may even appear 500 wrong question...

(This problem may be related toChen WeiliangThe region where the blog server is located)

Or, you can test it yourself to see how?

Comment

Your email address will not be published. Required fields * Callout

Scroll to Top