Skip to content

Commit fb4b748

Browse files
committed
refactor(scripts): update language configuration
1 parent 82075eb commit fb4b748

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

scripts/update_lang.py

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -50,32 +50,27 @@ def translate_text(text, target_language, special=False):
5050
return text
5151
print(f" Translating text: {text[:50]}...")
5252

53-
retries = 3
54-
for attempt in range(retries):
55-
try:
56-
response = client.chat.completions.create(
57-
model=MODEL_NAME,
58-
messages=[
59-
{"role": "system", "content": create_translation_prompt(target_language, special)},
60-
{"role": "user", "content": text}
61-
],
62-
stream=False
63-
)
64-
if not response or not response.choices or not response.choices[0].message.content:
65-
print(f" Error: Translation response is empty or invalid: {response}")
66-
if response and response.choices:
67-
translated_text = response.choices[0].message.content
68-
return translated_text
69-
else:
70-
print(f" Translation failed on attempt {attempt + 1}.")
71-
if attempt == retries - 1:
72-
return None
73-
except Exception as e:
74-
print(f" Translation failed with error on attempt {attempt + 1}: {e}")
75-
if attempt == retries - 1:
76-
return None
77-
time.sleep(1) # Wait before retrying
78-
return None
53+
try:
54+
response = client.chat.completions.create(
55+
model=MODEL_NAME,
56+
messages=[
57+
{"role": "system", "content": create_translation_prompt(target_language, special)},
58+
{"role": "user", "content": text}
59+
],
60+
stream=False
61+
)
62+
if not response or not response.choices or not response.choices[0].message.content:
63+
print(f" Error: Translation response is empty or invalid: {response}")
64+
return None
65+
if response and response.choices:
66+
translated_text = response.choices[0].message.content
67+
return translated_text
68+
else:
69+
print(f" Translation failed.")
70+
return None
71+
except Exception as e:
72+
print(f" Translation failed with error: {e}")
73+
return None
7974

8075
def translate_front_matter(front_matter, target_language, input_file):
8176
print(f" Translating front matter for: {input_file}")

0 commit comments

Comments
 (0)