From 08b8047719d6d9408f83e2360abbceb3d2eb7ce2 Mon Sep 17 00:00:00 2001 From: SinclairLin Date: Mon, 16 Feb 2026 02:16:36 +0800 Subject: [PATCH] ci: keep English README language switch line fixed --- .github/workflows/a18n.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/a18n.yml b/.github/workflows/a18n.yml index be01d64..398ead7 100644 --- a/.github/workflows/a18n.yml +++ b/.github/workflows/a18n.yml @@ -55,11 +55,19 @@ jobs: with open("README.zh-CN.md", "r", encoding="utf-8") as f: source = f.read() + lines = source.splitlines() + # README.md should always keep English-first switch line. + lang_switch = "English | [中文](./README.zh-CN.md)" + body = source + if lines and ("English" in lines[0] and "README.md" in lines[0]): + body = "\n".join(lines[1:]).lstrip("\n") + prompt = ( "Translate the following Markdown from Chinese to English. " + "Do not add or modify language-switch lines. " "Keep Markdown structure, headings, code blocks, commands, links, and file paths unchanged. " "Translate natural language only. Return Markdown only.\n\n" - + source + + body ) resp = client.chat.completions.create( @@ -71,7 +79,8 @@ jobs: ], ) - text = (resp.choices[0].message.content or "").strip() + "\n" + translated_body = (resp.choices[0].message.content or "").strip() + text = f"{lang_switch}\n\n{translated_body}\n" with open("README.md", "w", encoding="utf-8") as f: f.write(text) PY