Valla üşendim. Bende chatgptye sordum.
import openai
from tqdm import tqdm
import time
# OpenAI API anahtarınızı girin
openai.api_key = "api_kodum"
# Çevirilecek .po dosyası yolu
input_file_path = "F:\\WEBSITE\\dil\\messages.po"
# Çevirilerin kaydedileceği .po dosyası yolu
output_file_path = "F:\\WEBSITE\\dil\\messages-turkce.po"
# Çevirilecek dizeleri depolamak için bir sözlük oluşturun
msgid_data = {}
# .po dosyasını okuma
with open(input_file_path, "r", encoding="utf-8") as po_file:
lines = po_file.readlines()
# .po dosyasını işleme
line_number = 0
for line in lines:
if line.startswith("msgid "):
msgid = line.strip().split('"')[1]
msgid_data[line_number] = {"msgid": msgid, "msgstr": ""}
elif line.startswith("msgstr "):
msgid_data[line_number]["msgstr"] = line.strip().split('"')[1]
line_number += 1
# OpenAI API'sine sorgu göndermek için bir işlev tanımlayın
def translate_text(text):
response = openai.Completion.create(
engine="gpt-3.5-turbo-instruct",
prompt=f"Translate the following English text to Turkish:\n{text}\n\n",
max_tokens=50,
n=1,
stop=None,
temperature=0.5,
echo=True
)
translation = response.choices[0].text.strip().split("\n")[1].strip()
return translation
# Çevirilecek dizelerin toplam sayısını hesaplayın
total_translations = len(msgid_data)
# Dizeleri çevirin ve ilerlemeyi görüntüleyin
for line_number, msgid_info in tqdm(msgid_data.items(), total=total_translations):
msgid = msgid_info["msgid"]
if msgid:
translation = translate_text(msgid)
msgid_data[line_number]["msgstr"] = translation
time.sleep(0.12) # Her istekten sonra 0.12 saniye bekleyin
# Çevirileri yeni dosyaya kaydedin
with open(output_file_path, "w", encoding="utf-8") as output_file:
for line_number, msgid_info in msgid_data.items():
output_file.write(f'msgid "{msgid_info["msgid"]}"\n')
output_file.write(f'msgstr "{msgid_info["msgstr"]}"\n')
print("Çeviri tamamlandı ve yeni .po dosyasına kaydedildi.")İşte sonuç böyle bi deneyin hocam
hocam belirttim zaten yapay zekadan yaptığımı kendisi ile 2-3 saattir uğraşıyorum sağolsun beni anlamıyordu, bir arkadaş bir site önerdi:
https://chat.deepseek.com/coder diye burada şak diye çözdü sorunumu, teşekkür ederim yine de ilginiz için