From 5d42c818cf88317c054fecf04886b1877ba373f1 Mon Sep 17 00:00:00 2001 From: HU Xin Date: Fri, 13 Sep 2024 15:42:41 +0200 Subject: [PATCH] feat:Gemini translation prompt --- assets/flutter_i18n/en.json | 2 +- assets/flutter_i18n/translate.py | 28 ++++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/assets/flutter_i18n/en.json b/assets/flutter_i18n/en.json index edf561f9..d2f139c4 100644 --- a/assets/flutter_i18n/en.json +++ b/assets/flutter_i18n/en.json @@ -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", diff --git a/assets/flutter_i18n/translate.py b/assets/flutter_i18n/translate.py index 5dd7cde1..54e7b5b9 100644 --- a/assets/flutter_i18n/translate.py +++ b/assets/flutter_i18n/translate.py @@ -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 = {