Skip to content

Commit

Permalink
Added --detail-lang
Browse files Browse the repository at this point in the history
  • Loading branch information
pescheck-bram committed Sep 9, 2024
1 parent 41db4aa commit 17d635d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions python_gpt_po/po_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,18 @@ def perform_translation_without_validation(self, text, target_language, detail_l
"""Performs translation without validation for single words or short phrases."""
# Use the detailed language name if provided, otherwise use the short code
target_lang_text = detail_language if detail_language else target_language

prompt = (
f"Translate this single word or short phrase from English to {target_lang_text}. "
"Return only the direct translation without any explanation, additional text, or repetition. "
"If the word should not be translated (like technical terms or names), return it unchanged:\n"
)

message = {
"role": "user",
"content": prompt + text
}

try:
completion = self.config.client.chat.completions.create(
model=self.config.model,
Expand Down Expand Up @@ -226,7 +226,7 @@ def get_translation_prompt(target_language, is_bulk, detail_language=None):
"""Returns the appropriate translation prompt based on the translation mode."""
# Use detailed language if provided, otherwise use the short target language code
target_lang_text = detail_language if detail_language else target_language

if is_bulk:
return (
f"Translate the following list of texts from English to {target_lang_text}. "
Expand Down Expand Up @@ -467,7 +467,7 @@ def main():
# Ensure if --detail-lang is provided, its length matches --lang
if args.detail_lang:
detail_langs = args.detail_lang.split(',')

if len(lang_codes) != len(detail_langs):
raise ValueError("The number of languages in --lang and --detail-lang must match.")
else:
Expand Down

0 comments on commit 17d635d

Please sign in to comment.