There is no problem not worth solving, and no technology not worth learning!

WordPress tag cleaning practice (2): Go script engineering implementation

在宿主机的 output 目录下可以找到生成的 tag_mapping_result.csv。打开文件查看,结果格式规整,符合预期。

Practical Guide to Making a WordPress Blog Multilingual

查看按语言划分的用户统计,排名前 4 的语言(英语、中文、印尼语、越南语)(如图3)

(1) Blog Multilingual Decision | Why did I decide to spend time doing multilingual? (with real discovery)

Blog multi-language plug-in selection|Free VS payment, server VS browser, measured comparison + configuration tutorial

(2) Blog multi-language plug-in selection|Free VS payment, server VS browser, measured comparison + configuration tutorial

附上我翻译完成后的分类效果截图(如图11),中文与英文的分类总数相等

(3) Blog Category Translation Practice | 695 categories, 4-hour manual translation whole process (Guide to the pit)

最后分别查看中文与英文后台下的标签统计,符合预期。如图17

(4) Blog Label Translation Practice | 8060 tags, the whole process based on PHP scripts

如图11:最终效果,在前台,语言切换器的显示

(5) Blog menu translation practice

如图20对应场景:网站前台效果,顶部语言切换器(中文/英文),点击英文后,网站整体切换为英文版本,文章列表按发布时间倒序排列(与中文文章排序一致),点击任意英文文章,可正常查看,语言切换流畅;同时,英文文章的发布时间、分类、标签与中文原文完全对应,URL路径规范,SEO友好。

(6) WordPress Multilingual Blog Article Translation Practical Records (Polylang plugin, attached guide)

配图说明(如图10):中文、英文分类管理页面截图(分屏对比),标注两个页面的分类总数,演示数量一致/不一致的场景。

(7) WordPress adds article classification labels multi-language pre-translation process

完成后,访问中文系列页 https://你的域名/series/self-hosted-vpn-series/,点击顶部的 English 切换按钮,就能正常跳转到 https://你的域名/en/series/self-hosted-vpn-series-en/ 了。如图13

(8) Farewell Manual Numbering: Elegantly Manage WordPress Series Articles with PublishPress Series

WordPress Classic Editor Block Non-Destructive Migration: Batch Convert SyntaxHighlighter Shortcodes to Gutenberg Blocks

(9) WordPress Classic Editor Block Non-Destructive Migration: Batch Convert SyntaxHighlighter Shortcodes to Gutenberg Blocks

After clicking the translation button, you will encounter a pop-up window “mysterious” flashback problem and solution

(10) After clicking the translation button, you will encounter a pop-up window “mysterious” flashback problem and solution

中文标签出现冗余新增(如图2),数据彻底错乱。

(11) WP 6.9 Tag Synchronization Script In WP 7.0 Complete Troubleshooting and Solution Records

重点避坑:仅勾选数据库无法完成数据还原,选中库之后,右侧数据表列表点击全选,囊括库内所有数据表(如图3)

(12) Alibaba Cloud RDS database is damaged by misoperation, complete backup and recovery practical pit guide

为了看起来更完善,AI会主动新增非必要的清理、校验、适配逻辑,简单需求复杂化,大幅增加报错和风险概率(如图7)

(13) AI generates code to avoid the pit: the database operation code must not be directly executed online

WordPress Label Cleanup Practice (1): Failed attempts to match the big language model

(14) WordPress Label Cleanup Practice (1): Failed attempts to match the big language model

在宿主机的 output 目录下可以找到生成的 tag_mapping_result.csv。打开文件查看,结果格式规整,符合预期。

(15) WordPress tag cleaning practice (2): Go script engineering implementation

脚本执行后(如 图 6 终端日志所示),系统开始成对合并中英文标签。

(16) WordPress Label Cleanup Practice (3): Perfectly solve the problem of Polylang synonymous tag merger

图7:展示了浏览器开发者工具Network面板中,旧URL 301跳转至新URL的成功记录

(17) WordPress tag cleaning practice (4): Realize WordPress Chinese and English tag merge and URL automatic jump based on Go script

截图 5:验证 301 跳转

(18) WordPress tag cleaning practice (5): Solve the problem of Chinese labels remaining in the English language based on the php/go script, and realize the automatic tag merge and url jump

脚本显示处理了 8324 个标签

(19) Troubleshooting and Repairing the Accuracy of WP Label Batch Translation Scripts

图5:DeepL API 注册页面,国家或地区列表中没有中国大陆

(20) Why Is It So Hard to Improve English Translation Quality for a WordPress Blog in Mainland China? A Polylang, AutoPoly, and DeepL API Troubleshooting Recap

图5:DeepSeek 的评分结果截图

(21) Chrome Built-in AI vs Yandex Translate vs ChatGPT Plus: Why I’m Moving Important English Blog Posts to ChatGPT Plus

[截图 2:浏览器 Network 中直接请求 translate.yandex.net]

(22) From AutoPoly to Yandex Web: Validating Automatic English Translation Quality for WordPress

【图1:AutoPoly Free 与 Pro 功能对比截图】

(23) Can AutoPoly Pro + OpenAI API Automate WordPress English Translation? A Feasibility Analysis from Workflow to Payment

【图2:点击“立即试用”后,ChatGPT 输入框中出现“代理模式”】

(24) Can ChatGPT Agent Replace ChatGPT Plus for WordPress English Translation Rewrites?

InPrevious articleWe have verified that the large language model is not competent for the precise matching of a large amount of structured data. To be completely cleared /en/tag/ For the Chinese redundant URL under the path, we must return to the engineering scheme.

This article will be used as a practical tutorial, how to start from scratch, and complete the automated mapping processing of tags through the Go language combined with Baidu Translation API.


Step 1: Apply for Baidu Translation API voucher

In order to realize the accurate conversion of Chinese labels to English, we need to use mature machine translation services. Here is the Baidu Translation open platform, which provides the basic general text translation API, and the standard version has a free quota per month, which is fully enough for this cleaning task.

Log in to Baidu Translation Open Platform, and open the ‘General Text Translation’ service on the console.

Log in to Baidu Translation Open Platform, and open the "General Text Translation" service on the console.

After opening, enter the developer center, get your App ID And key. Please keep these two vouchers properly, and the subsequent code will be called as an environment variable.

After opening, enter the developer center and get your App ID and key on this page.

Step 2: Initialize the project on GitHub

Specification works start with version control. Create a new repository on GitHub, named Tag-merge. To simplify the initialization process, check Add README.mdand in .gitignore Select from template go, which will automatically help us ignore the binary files generated by compilation.

Create a new repository on GitHub, named tag-merge. In order to simplify the initialization process, check Add README.md, and select Go in the .gitignore template, which will automatically help us ignore the binary files generated by compilation.

After cloning the repository to the local, we enter the project directory in the terminal, ready to build the development environment.

Step 3: Project environment construction and code writing

In order to ensure the consistency of the environment and do not pollute the host, we use Docker for containerized development. The core directory structure of the project is as follows:

tag-merge/
├── .devcontainer/          # 容器开发环境配置(可选)
│   ├── devcontainer.json   # 容器开发环境配置文件
├── data/                   # 存放从数据库导出的原始 CSV 文件
│   ├── zh_tags.csv         # 中文标签库
│   └── en_tags.csv         # 英文标签库
├── output/                 # 存放程序运行后生成的结果文件
│   └── tag_mapping_result.csv
├── .env.example            # 环境变量示例文件
├── .env                    # 环境变量真实文件(已被 .gitignore 忽略)
├── .gitignore
├── docker-compose.yml
├── Dockerfile
├── go.mod
├── main.go                 # 核心业务逻辑
└── README.md

1. Configure environment variables

Create in the project root directory .env file, fill in the Baidu API credentials just obtained:

BAIDU_APP_ID=你的APPID
BAIDU_SECRET_KEY=你的密钥

2. Orchestrate Docker containers

Write docker-compose.yml, will .env The variables in the container environment are injected into the container environment, and at the same time data And output Directory to communicate with files.

3. Writing Core Go Logic

main.go The core processing process is as follows:

  1. read and parse en_tags.csv, with the label name and slug as the key, to build the hash index.
  2. read and iterate zh_tags.csv Each line in Chinese tags.
  3. Call Baidu Translate API to translate the Chinese label name into English.
  4. Crash the translation results in the English label index.
  5. If it hits, it is recorded as ‘API matching success’; if missed, the translation result is reserved and recorded as ‘API is not matched (Slug is recommended)’.
  6. Write the full result to output/tag_mapping_result.csv, in order to prevent Excel garbled characters, output the UTF-8 BOM header before writing.

At the same time, taking into account the QPS limit of Baidu Translation Standard Edition (1 time per second), the loop of the code has been added 1.1 second of sleeping intervals.

Step 4: Run the script and data processing

Execute the following commands in the terminal, start the container and run the script:

# 构建并后台启动容器
docker compose up -d --build

# 进入容器终端
docker exec -it tag-merge sh

# 在容器内初始化依赖
go mod tidy

# 执行处理脚本
go run main.go

After the script is run, it takes about 65 minutes to process 3592 pieces of data due to the 1.1 second frequency limit sleep. The progress and matching situation can be clearly seen from the terminal log.

After waiting patiently, the final output of the script is completed. The prompt: a total of 3592 pieces are processed, and 277 successfully collided.

After waiting patiently, the final output of the script is completed promptly:A total of 3592 pieces were processed, and 277 successfully collided. This means that there are 277 Chinese labels that have found an exact correspondence in the English library, and can be merged directly.

Step 5: Verify the processing results

Exit the container, we are in the host output The generated ones can be found in the directory tag_mapping_result.csv. Open the file to view, the result format is regular and in line with expectations.

The generated tag_mapping_result.csv can be found in the output directory of the host. Open the file to view, the result format is regular and in line with expectations.

There are five core fields in the CSV file:

  • Source tag ID / source tag name: The original Chinese label information.
  • Target Label ID / Target Label Name: Match the successful English tag information.
  • Status:
  • API matching success: The translated English has been found in the library (such as: Alipay -> Alipay), which is the highest priority processing item, which can be merged directly in WordPress.
  • API is not matched (slug is recommended): There is no such tag in the English library, but an accurate English translation is provided (such as: slow loading speed -> slow loading speed), which can be used as a reference for subsequently adding English tags.

Summary

Through the combination of Go script and Baidu translation API, we have replaced the uncontrollable large model in a deterministic engineering way, and successfully completed the preliminary cleaning of multi-language labels. 277 accurate match results provide reliable data support for subsequent database operations.

However, 277 only accounted for 7.7% of the full data, and there are still a large number of long-tail labels that need to be further screened and processed. In the next article, I will share how to safely perform tag merge and delete operations in WordPress based on this CSV result, completely eliminated /en/tag/ The Chinese redundant URL below.

WordPress Label Cleanup Practice (1): Failed attempts to match the big language model WordPress Label Cleanup Practice (3): Perfectly solve the problem of Polylang synonymous tag merger

WordPress Maintenance, Performance Optimization & Blog Growth Consulting

I have been running my personal technology blog for more than 10 years and have published over 1,000 original articles. My long-term practice covers WordPress website maintenance, CDN / Cloudflare configuration, caching optimization, Google SEO, ad monetization, and multilingual website operations.

If your WordPress website is slow, unstable, affected by plugin conflicts, showing caching issues, having AdSense display problems, or facing CDN / Cloudflare / DNS configuration uncertainty, feel free to contact me for remote troubleshooting.

Ideal For:
✅ Personal blog owners
✅ WordPress website operators
✅ Independent developers and content creators
✅ SaaS website owners
✅ Website owners who want better speed and stability

What I Offer:
✅ WordPress performance optimization
✅ Cloudflare / CDN / caching configuration checks
✅ Plugin conflict and layout issue troubleshooting
✅ AdSense display issue troubleshooting
✅ Basic SEO structure review
✅ Blog growth and monetization consulting

If you would like to discuss your website, please contact me and mention: WordPress Maintenance Consultation.

Contact Me:
Telegram: @shuijingwan
WeChat: 13980074657
Email: shuijingwanwq@gmail.com

评论

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.