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?

Hope Chen Weiliang Blog ( https://www.chenweiliang.com/ ) shared "What should I do if the WP Slug Translate plugin fails?Add the code to translate the article alias to English", it will help you.

Welcome to share the link of this article:https://www.chenweiliang.com/cwl-443.html

Welcome to the Telegram channel of Chen Weiliang's blog to get the latest updates!

🔔 Be the first to get the valuable "ChatGPT Content Marketing AI Tool Usage Guide" in the channel top directory! 🌟
📚 This guide contains huge value, 🌟This is a rare opportunity, don’t miss it! ⏰⌛💨
Share and like if you like!
Your sharing and likes are our continuous motivation!

 

Comment

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

scroll to top