mirror of
https://github.com/kejilion/sh.git
synced 2025-10-03 23:34:20 +08:00
Update translate.yml
This commit is contained in:
parent
020e2668d2
commit
73acd7114e
1 changed files with 16 additions and 34 deletions
50
.github/workflows/translate.yml
vendored
50
.github/workflows/translate.yml
vendored
|
@ -1,3 +1,4 @@
|
|||
|
||||
name: Weekly Translation Workflow
|
||||
|
||||
on:
|
||||
|
@ -6,9 +7,11 @@ on:
|
|||
- cron: '0 2 * * 0'
|
||||
workflow_dispatch: # 允许手动触发
|
||||
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
|
||||
jobs:
|
||||
translate:
|
||||
runs-on: ubuntu-latest
|
||||
|
@ -73,29 +76,22 @@ jobs:
|
|||
return re.sub(r'(?:\'[^\']*\'|"[^"]*")', repl, line)
|
||||
|
||||
def translate_file(input_file, output_file, target_lang):
|
||||
print(f"🔄 Translating to {target_lang}...")
|
||||
print(f"Translating to {target_lang}...")
|
||||
|
||||
if not os.path.exists(input_file):
|
||||
print(f"❌ Error: Input file {input_file} not found")
|
||||
print(f"Error: Input file {input_file} not found")
|
||||
return False
|
||||
|
||||
total_lines = sum(1 for _ in open(input_file, 'r', encoding='utf-8'))
|
||||
processed_lines = 0
|
||||
translated_count = 0
|
||||
|
||||
# 进度报告间隔(每处理10%显示一次)
|
||||
progress_interval = max(1, total_lines // 10)
|
||||
|
||||
with open(input_file, 'r', encoding='utf-8') as f_in, \
|
||||
open(output_file, 'w', encoding='utf-8') as f_out:
|
||||
|
||||
for line in f_in:
|
||||
processed_lines += 1
|
||||
|
||||
# 只在特定间隔显示进度
|
||||
if processed_lines % progress_interval == 0 or processed_lines == total_lines:
|
||||
progress = processed_lines / total_lines * 100
|
||||
print(f" Progress: {progress:.0f}%")
|
||||
progress = processed_lines / total_lines * 100
|
||||
print(f"\rProcessing: {progress:.1f}% ({processed_lines}/{total_lines})", end='')
|
||||
|
||||
leading_space = re.match(r'^(\s*)', line).group(1)
|
||||
stripped = line.strip()
|
||||
|
@ -106,23 +102,17 @@ jobs:
|
|||
if comment_text:
|
||||
translated = translate_text(comment_text, target_lang)
|
||||
f_out.write(f"{leading_space}{comment_mark} {translated}\n")
|
||||
translated_count += 1
|
||||
else:
|
||||
f_out.write(line)
|
||||
elif any(cmd in stripped for cmd in ['echo', 'read', 'send_stats']) and is_chinese(stripped):
|
||||
translated_line = translate_line_preserving_variables(line, target_lang)
|
||||
f_out.write(translated_line)
|
||||
translated_count += 1
|
||||
else:
|
||||
f_out.write(line)
|
||||
|
||||
original_size = os.path.getsize(input_file)
|
||||
translated_size = os.path.getsize(output_file)
|
||||
|
||||
print(f"✅ Translation to {target_lang} completed!")
|
||||
print(f" 📄 Lines processed: {total_lines}")
|
||||
print(f" 🔤 Lines translated: {translated_count}")
|
||||
print(f" 📊 File size: {original_size} → {translated_size} bytes")
|
||||
print(f"\nTranslation to {target_lang} completed.")
|
||||
print(f"Original file size: {os.path.getsize(input_file)} bytes")
|
||||
print(f"Translated file size: {os.path.getsize(output_file)} bytes")
|
||||
return True
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -140,32 +130,22 @@ jobs:
|
|||
|
||||
for dir_name, lang_code in languages.items():
|
||||
output_file = f'{dir_name}/kejilion.sh'
|
||||
print(f"\n📁 Processing {dir_name.upper()} translation...")
|
||||
|
||||
if translate_file(input_file, output_file, lang_code):
|
||||
success_count += 1
|
||||
print(f"✅ Successfully created {output_file}")
|
||||
print(f"✓ Successfully translated to {dir_name}")
|
||||
else:
|
||||
print(f"❌ Failed to create {output_file}")
|
||||
|
||||
print("─" * 60)
|
||||
print(f"✗ Failed to translate to {dir_name}")
|
||||
print("-" * 50)
|
||||
|
||||
print(f"\n🎉 Translation Summary: {success_count}/{len(languages)} languages completed")
|
||||
print(f"\nTranslation summary: {success_count}/{len(languages)} languages completed")
|
||||
|
||||
if success_count == 0:
|
||||
print("❌ All translations failed!")
|
||||
sys.exit(1)
|
||||
elif success_count < len(languages):
|
||||
print("⚠️ Some translations failed, but continuing...")
|
||||
else:
|
||||
print("✅ All translations completed successfully!")
|
||||
EOF
|
||||
|
||||
- name: Run translation
|
||||
run: |
|
||||
echo "🚀 Starting translation process..."
|
||||
python translate.py
|
||||
echo "🏁 Translation process completed!"
|
||||
|
||||
- name: Check for changes
|
||||
id: check_changes
|
||||
|
@ -213,3 +193,5 @@ jobs:
|
|||
else
|
||||
echo "**Changes:** No changes detected" >> $GITHUB_STEP_SUMMARY
|
||||
fi
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue