Skip to content

Commit

Permalink
feat:Gemini translation prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
HU Xin authored and HU Xin committed Sep 13, 2024
1 parent 572d798 commit 5d42c81
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion assets/flutter_i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
"export_wallet_logs": "Export wallet logs",
"diagnosing_logs": "To assist others in diagnosing your issue, please download and provide the transaction logs from your wallet. This information can offer valuable insight into the nature of the problem you're encountering.",
"export_logs": "Export logs",
"contact_chatgpt_support": "Contact MXC-GPT support",
"contact_chatgpt_support": "Contact Moon-GPT support",
"jump_to_telegram": "Jump to Telegram",
"custom_network": "Custom Network",
"mainnet": "Mainnet",
Expand Down
28 changes: 24 additions & 4 deletions assets/flutter_i18n/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,30 @@
# Function to translate text using Gemini
def translate(text, target_language):
model = genai.GenerativeModel("gemini-1.5-flash")
response = model.generate_content(
[f"this is an API, please just translate the following English text to {target_language}: {text}"]
)
return response.text.strip()
try:
response = model.generate_content(
f"""You are a translator API. Your task is to translate the following text.
CRITICAL INSTRUCTIONS:
1. Do NOT translate any text enclosed in curly braces {{ }}. These are placeholders and must remain exactly as they are.
2. Treat all curly braces {{ }} as literal text. They are NOT format specifiers.
3. Translate ONLY the actual text content outside of curly braces.
4. Preserve ALL formatting, special characters, and placeholders in their original form.
5. Provide ONLY the translated text as your response, without any additional comments, explanations, or quotation marks.
Original text (in English):
{text}
Translate the above text to {target_language}."""
)
print(response)
if response.parts:
return response.parts[0].text.strip()
else:
raise ValueError("No translation generated")
except Exception as e:
print(f"Translation error for '{text}': {str(e)}")
return text # Return original text if translation fails

def main():
language_dict = {
Expand Down

0 comments on commit 5d42c81

Please sign in to comment.