Update translation AI reference and remove translation files
Replaced references to DeepSeek AI with Qwen-MT-Plus AI in all README translations. Removed obsolete translation cache and PO/MO files for English, French, Korean, Persian, and Russian, and updated translate.py accordingly.
This commit is contained in:
+20
-16
@@ -52,36 +52,40 @@ def contains_chinese(text):
|
||||
# print(f"Language detection failed: {e}")
|
||||
# return False
|
||||
|
||||
def translate_text_deepseek(text, target_lang):
|
||||
def translate_text_qwen_mt(text, target_lang):
|
||||
api_key = os.getenv("AI_API_KEY")
|
||||
if not api_key:
|
||||
raise ValueError("AI_API_KEY environment variable is not set.")
|
||||
|
||||
client = OpenAI(
|
||||
api_key=api_key,
|
||||
base_url="https://api.deepseek.com",
|
||||
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
|
||||
)
|
||||
messages = [
|
||||
{'role': 'user', 'content': text}
|
||||
]
|
||||
translation_options = {
|
||||
"source_lang": "zh", # 指定源语言为中文
|
||||
"target_lang": target_lang
|
||||
}
|
||||
try:
|
||||
completion = client.chat.completions.create(
|
||||
model="deepseek-chat",
|
||||
messages=[
|
||||
{'role': 'system', 'content': 'You are a professional text translation assistant, focused on translating short Chinese texts into voice content in the specified target language. Your task is to translate only the Chinese parts of the text into the corresponding target language, leaving English portions as they are. The translation process should not consider context between sentences; ensure each individual sentence is translated accurately. Avoid adding any punctuation at the end of the translated sentences. The goal is to assist in the internationalization of scripts while ensuring translations are concise and accurate.Translation does not need to be bound by grammar, the simpler the better.'},
|
||||
{'role': 'user', 'content': f'Translate the following text to {target_lang}: {text}'}
|
||||
],
|
||||
stream=True
|
||||
model="qwen-mt-plus",
|
||||
messages=messages,
|
||||
extra_body={
|
||||
"translation_options": translation_options
|
||||
}
|
||||
)
|
||||
full_content = ""
|
||||
for chunk in completion:
|
||||
full_content += chunk.choices[0].delta.content
|
||||
return full_content.capitalize().lower().rstrip('.,!?;:')
|
||||
translated_text = completion.choices[0].message.content
|
||||
return translated_text.capitalize().lower().rstrip('.,!?;:')
|
||||
except Exception as e:
|
||||
print(f"DeepSeek translation failed: {e}")
|
||||
print(f"Qwen-MT-Plus translation failed: {e}")
|
||||
return ""
|
||||
|
||||
def translate_text_google(text, target_lang):
|
||||
try:
|
||||
translator = Translator(service_urls=['translate.google.com'])
|
||||
translation = translator.translate(text, src='auto', dest=target_lang)
|
||||
translation = translator.translate(text, src='zh-cn', dest=target_lang) # 指定源语言为中文
|
||||
translated_text = translation.text
|
||||
return translated_text.capitalize().lower().rstrip('.,!?;:')
|
||||
except Exception as e:
|
||||
@@ -152,12 +156,12 @@ def translate_po_file(input_file, output_file, target_lang_code, target_lang_nam
|
||||
for attempt in range(max_retries):
|
||||
try:
|
||||
time.sleep(0.1) # 增加延迟以避免请求过快
|
||||
translated_text = translate_text_deepseek(msgid_text, target_lang_name)
|
||||
translated_text = translate_text_qwen_mt(msgid_text, target_lang_code)
|
||||
|
||||
# 检查翻译结果是否仍包含中文或需要回退翻译
|
||||
if (contains_chinese(translated_text) or
|
||||
needs_fallback_translation(translated_text)):
|
||||
print(f"Translation does not meet criteria using DeepSeek. Using Google Translate...")
|
||||
print(f"Translation does not meet criteria using Qwen-MT-Plus. Using Google Translate...")
|
||||
translated_text = translate_text_google(msgid_text, target_lang_code)
|
||||
|
||||
# 清理Google翻译结果
|
||||
|
||||
Reference in New Issue
Block a user