没有不值得去解决的问题,也没有不值得去学习的技术!

Troubleshooting Long-Text Translation With SlyTranslate and Zhipu GLM-5.2: From 600-Second Timeouts to Full English WordPress Articles

【图 7,SlyTranslate 显示翻译完成并创建文章 19426】

作者:

,

Recently, I started testing SlyTranslate with Zhipu GLM-5.2 to automatically create English translations for Chinese WordPress articles.

My goal was not simply to translate a few paragraphs of plain text, but to automatically translate a full-length, real-world WordPress technical article while meeting the following requirements:

  • Preserve the Gutenberg block structure;
  • Preserve images, links, and HTML;
  • Keep code blocks in their original form;
  • Automatically create the English article;
  • Automatically establish Polylang Chinese-English associations;
  • Minimize manual copying and reformatting.

The Chinese test article ID is 19372, and its body contains numerous images, lists, and code blocks, making it well-suited for a stress test.

Initially, the translation requests repeatedly returned 504 timeouts. After multiple rounds of log analysis, I found that the issue was not solely insufficient server execution time, but rather two overlapping problems:

  1. The max_tokens sent by SlyTranslate to GLM-5.2 was only 256;
  2. SlyTranslate used a threefold character length as the threshold for detecting runaway long text generation, which easily caused false positives when translating from Chinese to English.

After fixing these two issues, the article translation completed in about 9 minutes and successfully generated a structurally complete English article.

English article URL:

Plaintext
https://en.shuijingwanwq.com/2026/07/13/19426/

1. Test Environment

The primary environment used this time was as follows:

  • WordPress;
  • Polylang;
  • SlyTranslate;
  • Ultimate AI Connector for Compatible Endpoints;
  • Zhipu Open Platform;
  • GLM-5.2;
  • W3 Total Cache;
  • Code Block Pro;
  • Nginx;
  • PHP-FPM.

The Zhipu compatible API endpoint is:

Plaintext
https://open.bigmodel.cn/api/paas/v4

The model used is:

Plaintext
glm-5.2

To prevent the thinking process from consuming extra time and tokens, the thinking mode was disabled in the model configuration.

The translation rules I set for SlyTranslate mainly included:

  • Output only English content in the end;
  • Preserve the Gutenberg block structure;
  • Preserve HTML, URLs, domains, and plugin names;
  • Do not translate code blocks;
  • Maintain an objective tone for a technical blog;
  • Do not add or remove technical facts.
[Figure 1, SlyTranslate model configuration using Zhipu GLM-5.2]
[Figure 1, SlyTranslate model configuration using Zhipu GLM-5.2]

2. Initial Problem: Translation Returns 504 After Running for a Long Time

During the first test of translating the long article, SlyTranslate displayed a “translating” status for an extended period.

Initially, I adjusted the following timeout settings one after another:

  • PHP execution time;
  • PHP-FPM request_terminate_timeout;
  • Nginx fastcgi_read_timeout;
  • Nginx fastcgi_send_timeout.

Eventually, the relevant timeout limits for both PHP-FPM and Nginx were increased to 600 seconds.

However, even after waiting a full 10 minutes, the translation request still failed.

The PHP-FPM logs showed that the request was terminated after running for about 600 seconds:

Plaintext
POST /index.php?_locale=user

Nginx then returned:

Plaintext
504 Gateway Timeout

This indicated that the server did not crash at a specific moment; rather, the translation task simply did not complete within 600 seconds.

[Figure 2, SlyTranslate translation request ultimately returns 504]
[Figure 2, SlyTranslate translation request ultimately returns 504]

3. Zhipu Backend Data Reveals an Abnormal Request Pattern

After further reviewing the call logs on the Zhipu Open Platform, I found that a single translation task generated approximately:

  • 105 model requests;
  • 54,443 input tokens;
  • 26,986 output tokens.

Even more abnormally, the output tokens for many requests were exactly:

Plaintext
256

If this were just normal segmented translation, it is highly unlikely that a large number of requests would have the exact same output length consecutively.

This meant that the model was likely not finishing naturally, but was being forcibly truncated after hitting the output limit.

[Figure 3, Zhipu backend showing numerous requests with 256 output tokens]
[Figure 3, Zhipu backend showing numerous requests with 256 output tokens]

4. Adding HTTP Debugging Confirms the Root Cause

To confirm the actual request parameters SlyTranslate was sending to Zhipu, I temporarily created an MU Plugin to log the following information:

  • Model name;
  • max_tokens;
  • Whether thinking mode was enabled;
  • HTTP request duration;
  • finish_reason;
  • Input and output tokens.

The logs showed the original request parameters were:

Plaintext
model: glm-5.2
max_tokens: 256
thinking: null
chat_template_kwargs: {"enable_thinking":false}

The model’s response results were almost entirely:

Plaintext
finish_reason: length
completion_tokens: 256

This clearly demonstrated that:

GLM-5.2 was truncated every time its output reached 256 tokens.

Because the translated structure was incomplete, SlyTranslate’s content validation failed, causing it to continuously retry or re-split the requests.

Therefore, the task was not processing normally for 10 minutes, but was instead constantly executing a large number of truncated, invalid translations.

Simply increasing the PHP or Nginx timeout further could not truly solve the problem.

[Figure 4, max_tokens=256 and finish_reason=length in the debug logs]
[Figure 4, max_tokens=256 and finish_reason=length in the debug logs]

5. Adjusting GLM-5.2 Request Parameters via an MU Plugin

I did not directly modify SlyTranslate’s core translation workflow, but instead preserved its existing:

  • Gutenberg block parsing;
  • Content grouping;
  • HTML structure protection;
  • Translation result validation;
  • Polylang article association.

I only made minimal adjustments to the GLM-5.2 request parameters right before the final request was sent to Zhipu.

Created the file:

Plaintext
wp-content/mu-plugins/swq-glm52-translation-tuning.php

With the following content:

PHP
<?php
/**
 * Plugin Name: SWQ GLM-5.2 Translation Tuning
 * Description: Adjusts Zhipu GLM-5.2 request parameters used by SlyTranslate.
 */

defined( 'ABSPATH' ) || exit;

add_filter(
	'http_request_args',
	static function ( array $args, string $url ): array {
		$host = wp_parse_url( $url, PHP_URL_HOST );
		$path = wp_parse_url( $url, PHP_URL_PATH );

		if (
			'open.bigmodel.cn' !== $host
			|| false === strpos( (string) $path, '/chat/completions' )
		) {
			return $args;
		}

		$raw_body = $args['body'] ?? '';

		$body = is_string( $raw_body )
			? json_decode( $raw_body, true )
			: $raw_body;

		if (
			! is_array( $body )
			|| 'glm-5.2' !== ( $body['model'] ?? '' )
		) {
			return $args;
		}

		$body['thinking'] = array(
			'type' => 'disabled',
		);

		if (
			! isset( $body['max_tokens'] )
			|| (int) $body['max_tokens'] < 1024
		) {
			$body['max_tokens'] = 1024;
		}

		$encoded = wp_json_encode(
			$body,
			JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
		);

		if ( is_string( $encoded ) ) {
			$args['body'] = $encoded;
		}

		return $args;
	},
	PHP_INT_MAX - 10,
	2
);

This code only takes effect for requests that meet the following criteria:

  • The domain is open.bigmodel.cn;
  • The path contains /chat/completions;
  • The model name is glm-5.2.

It primarily accomplishes two adjustments:

Plaintext
thinking.type = disabled
max_tokens 最低调整为 1024

Here, 1024 is the maximum allowed output; it does not mean the model will generate 1024 tokens every time.

Subsequent logs showed that most normal translations only used a few dozen to just over two hundred output tokens.

6. Results After the First Fix: All 89 Requests Finish Normally

After restarting the translation, the request parameters in the logs changed to:

Plaintext
max_tokens: 1024
thinking: {"type":"disabled"}

The finish reason for all 89 responses was:

Plaintext
finish_reason: stop

The statistical results were:

Plaintext
stop: 89
length: 0

A single request typically took between 2 and 6 seconds, and the maximum output was only about 265 tokens.

This indicates that:

  • The 256-token truncation issue has been resolved;
  • The model can finish its output normally;
  • SlyTranslate’s chunked translation workflow has started working properly;
  • Continuing to increase max_tokens will not cause the model to meaninglessly generate longer content.

At this point, the translation progress bar in the browser was finally able to advance continuously.

[Figure 5, Translation progress bar advancing normally after fixing max_tokens]
[Figure 5, Translation progress bar advancing normally after fixing max_tokens]

7. Second Problem: SlyTranslate Flags Normal English Excerpt as Runaway Generation

Although requests were no longer being truncated, the first full translation still failed.

SlyTranslate returned the error:

Plaintext
The translated output is far longer than the source text,
indicating the model entered a runaway generation loop
or appended hallucinated content.

The corresponding internal error code was:

Plaintext
invalid_translation_runaway_output

After further reviewing TranslationValidator.php, I found that SlyTranslate used the following logic for longer texts:

PHP
private const MAX_RUNAWAY_OUTPUT_RATIO = 3;

The evaluation logic is equivalent to:

Plaintext
译文字符数 > 原文字符数 × 3

Once the length exceeds three times the original, it assumes the model may have entered runaway generation.

This limit might be somewhat lenient for similar Latin-based languages, but for Chinese-to-English translations, the character count ratio is not necessarily reliable.

8. Why Chinese-to-English Translations Easily Exceed Three Times the Character Count

The error this time was triggered by the article excerpt.

The Chinese excerpt length was:

Plaintext
254 个字符

The three times threshold was:

Plaintext
762 个字符

The English excerpt length returned by GLM-5.2 was approximately:

Plaintext
856 个字符

The actual ratio was approximately:

Plaintext
856 ÷ 254 ≈ 3.37

Looking at the English content, the model did not generate repetitive text, nor did it add a large amount of non-existent content.

This was simply because a single Chinese character has a higher information density, while English requires more words, spaces, and punctuation to convey the same meaning.

Therefore, the threefold character limit is prone to false positives for Chinese source articles.

[Figure 6, SlyTranslate returns "translated output is far longer" error]
[Figure 6, SlyTranslate returns “translated output is far longer” error]

9. Adjusting the Long Text Growth Threshold from 3 to 6

Considering that the source language for current and future articles will be Chinese, and the target language may not be limited to English in the future, I ultimately adjusted the threshold to:

PHP
private const MAX_RUNAWAY_OUTPUT_RATIO = 6;

Modified file:

Plaintext
wp-content/plugins/slytranslate/inc/TranslationValidator.php

Before modification:

PHP
private const MAX_RUNAWAY_OUTPUT_RATIO = 3;

After modification:

PHP
private const MAX_RUNAWAY_OUTPUT_RATIO = 6;

Backed up the original file before modifying:

Bash
cd /data/wwwroot/www.shuijingwanwq.com

file="wp-content/plugins/slytranslate/inc/TranslationValidator.php"
backup="${file}.bak-runaway-ratio-$(date +%F-%H%M%S)"

cp -a "$file" "$backup"

Checked PHP syntax after modification:

Bash
php -l wp-content/plugins/slytranslate/inc/TranslationValidator.php

Validation result:

Plaintext
No syntax errors detected

After setting the threshold to 6:

  • The current normal English excerpt at roughly 3.37 times the length can pass;
  • There is a larger margin when translating from Chinese to languages like German or French;
  • The 10x to 30x anomalous generation previously recorded by the plugin can still be intercepted.

It is worth noting that this adjustment directly modifies the SlyTranslate plugin file.

This value may be overwritten when the plugin is updated in the future and will need to be rechecked.

10. Final Translation Success

After starting the translation again, the task finally completed successfully.

This translation took approximately:

Plaintext
9 分 6 秒

SlyTranslate automatically created the English article:

Plaintext
文章 ID:19426
状态:publish

It also automatically completed:

  • English title generation;
  • English excerpt generation;
  • Body translation;
  • Featured image preservation;
  • Polylang Chinese-English article association;
  • English permalink generation.
[Figure 7, SlyTranslate shows translation complete and creates article 19426]
[Figure 7, SlyTranslate shows translation complete and creates article 19426]

11. Checking the Gutenberg Structure of the Chinese and English Articles

Successful translation does not guarantee complete content, so I proceeded to compare the Chinese and English articles using a server-side script.

Chinese article:

Plaintext
ID:19372

English article:

Plaintext
ID:19426

The main block statistics are as follows:

ItemChinese ArticleEnglish Article
Paragraphs127127
Headings2828
Images88
Lists1515
List Items7272
Code Block Pro5454
Gutenberg Opening Comments304304

After further extracting the Gutenberg block signatures, the results were:

Plaintext
中文签名数:608
英文签名数:608
区块顺序完全一致:是

This indicates that the English article did not suffer from:

  • Missing blocks;
  • Disordered block sequence;
  • Mismatched opening and closing comments;
  • Rewritten Gutenberg structure by the model.

12. Checking the 54 Code Block Pro Code Blocks

This article contains 54 wp:kevinbatdorf/code-block-pro blocks.

After serializing and comparing them one by one, the results were:

Plaintext
中文代码块:54
英文代码块:54
完全一致的代码块:54
发生变化的代码块:0

In other words, all 54 code blocks were preserved verbatim.

This is crucial for a technical blog.

Standard machine translation or full-text translation can easily modify:

  • Commands;
  • Domains;
  • URLs;
  • PHP code;
  • Bash commands;
  • JSON;
  • HTML;
  • Configuration file contents.

SlyTranslate’s block-level processing proved quite stable in terms of structural safety.

13. Checking the English Body for Residual Chinese

Finally, I tallied the distribution of Chinese characters in the English article.

The results were:

Plaintext
标题中文字符:0
摘要中文字符:0
代码块之外中文字符:0
存在中文的非代码区块:0

The remaining Chinese characters were all located within the verbatim preserved Code Block Pro blocks.

Therefore, it can be confirmed that:

  • The title has been fully translated;
  • The excerpt has been fully translated;
  • Standard paragraphs have been fully translated;
  • Headings and lists have been fully translated;
  • No body blocks were skipped;
  • Code blocks remained unchanged according to the original rules.

The ratio of the English plain text length to the Chinese plain text length was approximately:

Plaintext
1.75

This ratio also showed no signs of repetitive generation or abnormal content inflation across the entire article.

14. English Frontend Check

The English article frontend URL is:

Plaintext
https://en.shuijingwanwq.com/2026/07/13/19426/

After a manual check via the browser, the following issues have not been found so far:

  • Page failing to load;
  • Gutenberg block errors;
  • Missing images;
  • Disordered list structures;
  • Corrupted code blocks;
  • Table of contents anomalies;
  • Large sections of repeated content on the page.
[Figure 8, English article frontend page]
[Figure 8, English article frontend page]

15. Current Assessment of Translation Quality

From a technical workflow perspective, this test successfully demonstrated that:

  • Long articles can be translated;
  • The Gutenberg structure can be preserved;
  • Code blocks will not be modified;
  • Polylang associations work normally;
  • The English page is directly accessible.

However, regarding English expression quality, the articles generated by GLM-5.2 may still exhibit:

  • A few literal translations;
  • Some imprecise technical terminology;
  • Unnatural use of contextual logical connectors;
  • Slightly lengthy headings;
  • Chinese text remaining in plain text-style code blocks.

For example, “固定链接” in a Chinese context might sometimes be directly translated as:

Plaintext
permalinks

But in the specific context, it might actually be closer to:

Plaintext
hardcoded links

These issues do not currently affect the basic comprehension of the article, but there is still a gap before achieving a high-quality English re-translation that requires absolutely no manual review.

At present, I do not plan to invest another 10 to 20 minutes into English proofreading for each article.

If extensive manual corrections are still required, the efficiency gains from automatic translation will drop significantly, making it better to continue using ChatGPT Plus for full-article re-translation.

Therefore, at this stage, I will keep this proven technical solution and continue optimizing it in the following directions:

  • Adjusting the translation prompt;
  • Optimizing technical terminology rules;
  • Trying models better suited for technical articles;
  • Distinguishing between actual code and plain text output;
  • Optimizing title and excerpt generation;
  • Changing the length validation to a method better suited for Chinese source articles.

16. Disabling Temporary Debug Logs

After identifying the problem, I disabled the temporary HTTP debugging MU Plugin.

Executed:

Bash
cd /data/wwwroot/www.shuijingwanwq.com

mv \
  wp-content/mu-plugins/swq-slytranslate-http-debug.php \
  wp-content/mu-plugins/swq-slytranslate-http-debug.php.disabled

Also cleared the debug logs:

Bash
: > wp-content/slytranslate-http-debug.log

Final status:

Plaintext
swq-slytranslate-http-debug.php.disabled
slytranslate-http-debug.log:0 字节

The file used to adjust the GLM-5.2 parameters remains enabled:

Plaintext
wp-content/mu-plugins/swq-glm52-translation-tuning.php

Therefore, the following settings will continue to take effect:

Plaintext
thinking.type = disabled
max_tokens 最低为 1024

17. Conclusions Drawn from This Troubleshooting

1. Long Execution Time Does Not Necessarily Mean Insufficient Server Performance

Seeing 504 and PHP-FPM timeouts initially makes it easy to just keep increasing the execution time.

But the real problem was that every output was being truncated at 256 tokens.

Without checking the model’s actual requests and finish_reason, simply adjusting the server timeout makes it difficult to solve the root problem.

2. Both Request Count and Output Tokens Should Be Checked

The speed of a single request was not slow, but a large number of failed retries quickly accumulated total execution time.

The most valuable clue this time was:

Plaintext
大量请求的 completion_tokens 都恰好等于 256

This was more indicative of the problem than just observing the progress bar in the browser.

3. A Uniform Character Multiplier Is Not Suitable for All Language Pairs

The information density of Chinese characters differs from that of English.

Simply using:

Plaintext
译文字符数 > 原文字符数 × 3

easily misidentifies a normal Chinese-to-English translation as anomalous generation.

4. WordPress Technical Articles Cannot Be Checked Only for Translated Content

For articles containing numerous blocks and code, you also need to check:

  • The number of Gutenberg blocks;
  • Block sequence;
  • The number of images;
  • The number of lists;
  • The number of code blocks;
  • Code block contents;
  • Residual Chinese;
  • Actual frontend rendering results.

5. A Working Technical Pipeline and Passing Translation Quality Are Two Separate Issues

What has been solved this time is:

Whether SlyTranslate can stably complete long-article translations using GLM-5.2.

What is not fully solved yet is:

Whether the English quality can reach the level of my previous full-article re-translations using ChatGPT Plus, entirely without manual proofreading.

These two issues need to be evaluated separately.

Conclusion

After this troubleshooting process, SlyTranslate + Zhipu GLM-5.2 is now capable of translating a long WordPress technical article containing 54 code blocks, 8 images, and hundreds of Gutenberg blocks.

The final result performed excellently in terms of structural integrity:

  • 608 Gutenberg block signatures matched in sequence;
  • 54 Code Block Pro blocks matched verbatim;
  • No residual Chinese in the standard body text;
  • Normal Polylang Chinese-English association;
  • The English frontend page is accessible normally.

The two key issues that actually caused the failures were:

Plaintext
max_tokens = 256

And:

Plaintext
MAX_RUNAWAY_OUTPUT_RATIO = 3

After increasing GLM-5.2’s maximum output to 1024 and adjusting the long text growth threshold suitable for Chinese source articles to 6, the entire translation workflow finally worked end-to-end.

Currently, this solution provides a foundation for continued testing and optimization. However, whether it can completely replace manual full-article re-translation with ChatGPT Plus will require further observation of English quality and the degree of automation.

系列导航

需要长期技术维护或远程问题排查?

我是拥有 15+ 年经验的 PHP / Go 后端工程师,长期关注已有系统维护、Bug 修复、性能优化、服务器排查、WordPress 网站维护和小功能迭代。

如果你的项目遇到以下情况,可以先从一次小问题排查开始合作:

  • ✅ PHP / Laravel / Yii2 老项目无人维护
  • ✅ Go / Gin 后端接口需要排查或优化
  • ✅ WordPress 网站访问慢、报错或插件冲突
  • ✅ Nginx / MySQL / Redis / Linux 服务器异常
  • ✅ CDN / Cloudflare / DNS / HTTPS 配置问题
  • ✅ 需要长期远程技术支持或兼职维护

更多介绍请查看:关于我 & 合作

微信:13980074657
邮箱:shuijingwanwq@gmail.com
Telegram:@shuijingwan
GitHub:https://github.com/shuijingwan

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理