done 80/735 (10% not ~28% sorry) and 735/735 done (counted fuzzy or google translate helper). See https://gist.github.com/BlackCatOfficialytb/e85bad1758d9e29c349f2d75b91363f1 for program to help me translate

This commit is contained in:
blackcatofficial 2026-05-22 21:52:33 +07:00
parent 729bf9f644
commit 1d84684617
4 changed files with 1504 additions and 4282 deletions

View File

@ -1,68 +0,0 @@
import polib
from deep_translator import GoogleTranslator, DeeplTranslator
import re
import sys
# --- CẤU HÌNH ---
SOURCE_FILE = 'base.po'
TARGET_FILE = 'base_translated.po'
API_KEY = None # Thay bằng key của bạn nếu dùng DeepL
TARGET_LANG = 'vi'
MODE = 'google' # Chuyển thành 'deepl' nếu muốn dùng DeepL
def translate_text(text, mode='google', api_key=None):
if not text.strip():
return text
# Bảo vệ placeholders
placeholders = re.findall(r'(\{[^}]*\}|%s|%d)', text)
temp_text = text
for i, ph in enumerate(placeholders):
temp_text = temp_text.replace(ph, f" PH{i} ")
try:
if mode == 'deepl':
if not api_key:
raise ValueError("DeepL cần API Key!")
# Dùng thư viện deep-translator cho đồng bộ
translated_text = DeeplTranslator(api_key=api_key, source='en', target='vi').translate(temp_text)
else:
# Dùng Google qua deep-translator
translated_text = GoogleTranslator(source='en', target='vi').translate(temp_text)
# Khôi phục placeholders
for i, ph in enumerate(placeholders):
translated_text = re.sub(f"PH{i}", ph, translated_text, flags=re.IGNORECASE)
return translated_text.strip()
except Exception as e:
print(f"Lỗi: {e}")
return None
def main():
po = polib.pofile(SOURCE_FILE)
untranslated_entries = [entry for entry in po if not entry.msgstr and entry.msgid]
print(f"Tìm thấy {len(untranslated_entries)} câu chưa dịch. Bắt đầu xử lý...")
count = 0
for entry in untranslated_entries:
translated = translate_text(entry.msgid, mode=MODE, api_key=API_KEY)
if translated:
entry.msgstr = translated
# Đánh dấu fuzzy để mình biết đường mà soát lại
if 'fuzzy' not in entry.flags:
entry.flags.append('fuzzy')
count += 1
print(f"[{count}] Đã dịch: {entry.msgid[:30]}... -> {translated[:30]}...")
# Lưu định kỳ để tránh mất dữ liệu nếu lỗi mạng
if count % 10 == 0:
po.save(TARGET_FILE)
po.save(TARGET_FILE)
print(f"\nHoàn thành! Đã dịch {count} câu. File lưu tại: {TARGET_FILE}")
if __name__ == "__main__":
main()

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff