Remove English README and translation workflow
Deleted the auto-translation GitHub Actions workflow and the generated README.en.md file. Updated README.md, likely to remove references to the English version and translation automation.
This commit is contained in:
1 parent
f540bf1f1f
commit
9b461bf271
3 files changed
-2486
No files matched your search
@@ -1,186 +0,0 @@
|
||||
name: Translate README
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths:
|
||||
- "README.md"
|
||||
pull_request:
|
||||
branches: [main]
|
||||
paths:
|
||||
- "README.md"
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
translate-readme:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup Node.js for chunked translation
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "20"
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
npm install deepl-node
|
||||
|
||||
- name: Split and translate README in chunks
|
||||
run: |
|
||||
# 创建分块翻译脚本
|
||||
cat > translate_chunks.js << 'EOF'
|
||||
const fs = require('fs');
|
||||
const { Translator } = require('deepl-node');
|
||||
|
||||
const translator = new Translator(process.env.DEEPL_API_KEY);
|
||||
|
||||
async function translateFile() {
|
||||
try {
|
||||
const content = fs.readFileSync('README.md', 'utf8');
|
||||
|
||||
// 智能分块:按段落和标题分割,避免破坏结构
|
||||
const sections = content.split(/(?=^#{1,6}\s)/m);
|
||||
const chunks = [];
|
||||
let currentChunk = '';
|
||||
const maxChunkSize = 3800; // 字符数限制,留有安全边际
|
||||
|
||||
for (const section of sections) {
|
||||
if ((currentChunk + section).length > maxChunkSize && currentChunk) {
|
||||
chunks.push(currentChunk.trim());
|
||||
currentChunk = section;
|
||||
} else {
|
||||
currentChunk += section;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentChunk.trim()) {
|
||||
chunks.push(currentChunk.trim());
|
||||
}
|
||||
|
||||
console.log(`📄 文件大小: ${content.length} 字符`);
|
||||
console.log(`📦 分为 ${chunks.length} 块进行翻译`);
|
||||
|
||||
const translatedChunks = [];
|
||||
|
||||
for (let i = 0; i < chunks.length; i++) {
|
||||
const chunkSize = chunks[i].length;
|
||||
console.log(`🔄 翻译第 ${i + 1}/${chunks.length} 块 (${chunkSize} 字符)...`);
|
||||
|
||||
try {
|
||||
const result = await translator.translateText(
|
||||
chunks[i],
|
||||
'zh',
|
||||
'en-US',
|
||||
{
|
||||
preserveFormatting: true,
|
||||
tagHandling: 'html'
|
||||
}
|
||||
);
|
||||
translatedChunks.push(result.text);
|
||||
console.log(`✅ 第 ${i + 1} 块翻译完成`);
|
||||
|
||||
// 添加延迟避免API限制
|
||||
if (i < chunks.length - 1) {
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`❌ 翻译第 ${i + 1} 块时出错:`, error.message);
|
||||
// 如果翻译失败,保留原文并添加错误标记
|
||||
translatedChunks.push(`<!-- 翻译失败,保留原文 -->\n${chunks[i]}`);
|
||||
}
|
||||
}
|
||||
|
||||
const translatedContent = translatedChunks.join('\n\n');
|
||||
fs.writeFileSync('README.en.md', translatedContent);
|
||||
console.log('🎉 翻译完成!');
|
||||
|
||||
// 检查翻译质量
|
||||
const originalLines = content.split('\n').length;
|
||||
const translatedLines = translatedContent.split('\n').length;
|
||||
console.log(`📊 原文行数: ${originalLines}, 译文行数: ${translatedLines}`);
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 翻译过程中发生错误:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
translateFile();
|
||||
EOF
|
||||
|
||||
# 运行翻译脚本
|
||||
node translate_chunks.js
|
||||
env:
|
||||
DEEPL_API_KEY: ${{ secrets.DEEPL_API_KEY }}
|
||||
|
||||
- name: Update language link and add translation notice
|
||||
run: |
|
||||
if [ -f "README.en.md" ]; then
|
||||
# 创建临时文件
|
||||
temp_file=$(mktemp)
|
||||
|
||||
# 读取翻译后的文件内容
|
||||
content=$(cat README.en.md)
|
||||
|
||||
# 替换语言链接:将 [English](README.en.md) 改为 [汉语](README.md)
|
||||
content=$(echo "$content" | sed 's/\*\*\[English\](README\.en\.md)\*\*/\*\*\[汉语\](README\.md)\*\*/g')
|
||||
|
||||
# 在第三行(语言链接后)插入翻译说明
|
||||
echo "$content" | awk '
|
||||
NR==1 {print $0}
|
||||
NR==2 {print $0; print ""}
|
||||
NR==3 {
|
||||
print $0
|
||||
print ""
|
||||
print "> **📝 翻译说明**"
|
||||
print ">"
|
||||
print "> 本文档由 [DeepL](https://www.deepl.com/) 自动翻译生成,如有疏漏或错误,请以 [中文原文](README.md) 为准。"
|
||||
print ">"
|
||||
print "> This document is automatically translated by [DeepL](https://www.deepl.com/). For any omissions or errors, please refer to the [original Chinese text](README.md)."
|
||||
print ""
|
||||
next
|
||||
}
|
||||
NR>3 {print $0}
|
||||
' > "$temp_file"
|
||||
|
||||
# 替换原文件
|
||||
mv "$temp_file" README.en.md
|
||||
fi
|
||||
|
||||
- name: Commit and push changes
|
||||
run: |
|
||||
git config --local user.email "action@github.com"
|
||||
git config --local user.name "GitHub Action"
|
||||
|
||||
if [ -f "README.en.md" ]; then
|
||||
git add README.en.md
|
||||
if git diff --staged --quiet; then
|
||||
echo "No changes to commit"
|
||||
else
|
||||
# 计算文件统计信息
|
||||
original_lines=$(wc -l < README.md)
|
||||
translated_lines=$(wc -l < README.en.md)
|
||||
|
||||
git commit -m "🌐 Auto-translate README.md to English using DeepL (Chunked)
|
||||
|
||||
📄 Processed large README.md in chunks for optimal translation quality
|
||||
📊 Original: ${original_lines} lines → Translated: ${translated_lines} lines
|
||||
✨ Features:
|
||||
- Generated README.en.md from README.md
|
||||
- Updated language links
|
||||
- Added translation disclaimer
|
||||
- Intelligent chunk processing to maintain structure
|
||||
|
||||
Co-authored-by: DeepL <https://www.deepl.com/>"
|
||||
git push
|
||||
fi
|
||||
fi
|
||||
-2298
File diff suppressed because it is too large.
Load diff
@@ -1,7 +1,5 @@
|
||||
# Xget
|
||||
|
||||
**[English](README.en.md)**
|
||||
|
||||
[](#-生态系统集成)
|
||||
[](#-生态系统集成)
|
||||
[](#cloudflare-workers强烈推荐)
|
||||
|
||||
Reference in new issue
Block a user