Implementing One-Click Translation with Alfred

This article introduces how to implement one-click translation using Alfred, including translation advantages, implementation details, and related resources. These steps can help improve translation efficiency.

Oct 3, 2020 · 1 min read · 194 Words · -Views -Comments · Software & Tools
Productivity Tools 🇨🇳 阅读中文版
Read with AI

Choose an AI assistant

ChatGPT Open in a new tab with the article link and prompt
Claude Copy the prompt, then open Claude

Open Claude
Trouble reading the article?

If the prompt is missing, copy the full prompt below into your AI assistant. If the AI cannot read the article, paste the visible passage you want to discuss and add your question.

At a friend’s request, I implemented a workflow based on Baidu Translate API. Here’s a simple share of the process.

Translation Service

Since my friend specifically requested Baidu Translate, I chose Baidu. However, I personally prefer Google Translate as its translation quality is relatively better.

Using Baidu Translate service requires the following:

  • Register a Baidu account
  • Obtain APP ID and secret key, ensure the corresponding API service is activated

Activation URL: https://fanyi-api.baidu.com/product/113

Workflow Implementation

The entire implementation is simple - just request the API, get translation results, and display them in a user-friendly way.

If you’re interested, check out the source code. If not, just download what I’ve made.

Download link: Click here

Pitfall - 52003 Error

I encountered an issue during actual development, worth complaining about. Baidu’s poor quality is indeed well-known. According to the official API documentation, using POST throws an error, but GET works. I initially thought I was doing something wrong, checked the API several times, and after comparison found it was Baidu’s fault.

data: { error_code: '52003', error_msg: 'UNAUTHORIZED USER' }

Result

Final Thoughts

After all, it’s a free service, so if there’s instability, it’s most likely Baidu’s issue.

Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover