Skip to content

Commit

Permalink
修改翻译器
Browse files Browse the repository at this point in the history
  • Loading branch information
snjyor committed Feb 23, 2025
1 parent be325c3 commit e858179
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
10 changes: 7 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import os
from github import Github
from pathlib import Path
from googletrans import Translator
from deep_translator import GoogleTranslator
import requests
from tqdm import tqdm


REPO_PATH = Path(__file__).resolve().parent

translator = Translator()
translator = GoogleTranslator(source='auto', target='zh-CN')
GITHUB_TOKEN = os.getenv("GIT_TOKEN")
if not GITHUB_TOKEN:
raise ValueError("GIT_TOKEN is not set or is empty")
Expand Down Expand Up @@ -44,7 +44,11 @@ def get_repo_description(repo):
if repo_description and isinstance(repo_description, str):
if len(repo_description) > 100:
repo_description = repo_description[:100] + "..."
repo_description_zh = translator.translate(repo_description, dest="zh-CN").text
try:
repo_description_zh = translator.translate(repo_description)
except Exception as e:
print(f"翻译失败: {e}")
repo_description_zh = repo_description
# 整理成 Markdown 表格格式|项目名|项目链接|项目描述|中文项目描述|
markdown_content += f"|[{repo_name}]({repo_url})|{repo_description}|[{repo_name}]({repo_url})|{repo_description_zh}|\n"

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
googletrans==4.0.0rc1
# googletrans==4.0.0rc1
PyGithub==2.3.0
Requests==2.32.3
tqdm==4.66.4
deep-translator==1.11.4

0 comments on commit e858179

Please sign in to comment.