Skip to content

Commit 21b1385

Browse files
Changed default model to gpt-4o-mini
Prompt improvements
1 parent cdb8936 commit 21b1385

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

AndroidResourceTranslator.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
# ------------------------------------------------------------------------------
2222

2323
TRANSLATION_GUIDELINES = """\
24-
Follow the guidelines below closely.
25-
24+
Follow these guidelines carefully.
2625
Guidelines:
2726
1. **Purpose & Context:**
2827
The translation is for an Android application's UI. Use terminology and phrasing consistent with android applications. Do not change the meaning of the text.
@@ -49,29 +48,33 @@
4948
5. **Dialect and Regional Vocabulary:**
5049
Use native vocabulary for the specified dialect (e.g., **Português de Portugal**), avoiding terms from other variants.
5150
52-
6. **Output Requirements:**
51+
6. **General Note:**
52+
Preserve all proper nouns, feature names, and trademarked or branded terms in their original English form.
53+
54+
7. **Output Requirements:**
5355
Return ONLY the final translated text as a single plain line, preserving any required formatting from the source.
5456
5557
"""
5658

5759
PLURAL_GUIDELINES_ADDITION = """\
58-
6. **Plural Resources:**
60+
7. **Plural Resources:**
5961
For plural translations, if the source resource contains only a single plural key (e.g., "other") but the target language requires multiple plural forms, return all the appropriate plural keys for the target language.
6062
*Example:* If the English source is `<item quantity="other">%d day left</item>`, the Portuguese translation should include both `<item quantity="one">%d dia restante</item>` and `<item quantity="many">%d dias restantes</item>`. Ensure that each plural form reflects the proper singular and plural usage with the correct one, many etc as defined by the target language's standard usage. Use the target language's pluralization guidelines as a reference to determine which keys to include and their corresponding forms.
6163
The full set supported by Android is zero, one, two, few, many, and other.
6264
63-
7. **Output Requirements:**
65+
8. **Output Requirements:**
6466
Return ONLY a JSON object containing the translated plural mapping as a single plain line. Do not include any markdown formatting, code blocks, or additional commentary, except if any such formatting is already present in the source string provided.
6567
"""
6668

6769
SYSTEM_MESSAGE_TEMPLATE = """\
68-
You are a software engineer translating textual UI elements within a software application from English into {target_language} while keeping technical terms in English.
70+
You are a software engineer translating textual UI elements within an Android from English into {target_language} while keeping technical terms in English.
6971
"""
7072

7173
TRANSLATE_FINAL_TEXT = """\
72-
Translate the following resource for an Android app provided after the dashed line to the following values-{target_language}/string.xml language: {target_language}
74+
Translate the following resource for an Android app provided after the dashed line to the following values-{target_language}/string.xml for the language: {target_language}
7375
----------
7476
"""
77+
7578
# ------------------------------------------------------------------------------
7679
# Logger Setup
7780
# ------------------------------------------------------------------------------
@@ -354,7 +357,7 @@ def indent_xml(elem: ElementTree.Element, level: int = 0) -> None:
354357
# Translation & OpenAI API Integration
355358
# ------------------------------------------------------------------------------
356359

357-
def call_openai(prompt: str, system_message: str, api_key: str, model: str = "gpt-3.5-turbo") -> str:
360+
def call_openai(prompt: str, system_message: str, api_key: str, model: str) -> str:
358361
"""
359362
Helper function to call the OpenAI API with the given prompt and system message.
360363
Returns the response text.
@@ -613,7 +616,6 @@ def create_translation_report(translation_log):
613616
for lang, details in languages.items():
614617
report += f"### Language: {lang}\n\n"
615618
if details.get("strings"):
616-
report += "#### Strings\n\n"
617619
report += "| Key | Source Text | Translated Text |\n"
618620
report += "| --- | ----------- | --------------- |\n"
619621
for entry in details["strings"]:
@@ -654,7 +656,7 @@ def main() -> None:
654656
validate_translations = False
655657
log_trace = os.environ.get("INPUT_LOG_TRACE", "false").lower() == "true"
656658
openai_api_key = os.environ.get("OPENAI_API_KEY")
657-
openai_model = os.environ.get("INPUT_OPENAI_MODEL", "gpt-3.5-turbo")
659+
openai_model = os.environ.get("INPUT_OPENAI_MODEL", "gpt-4o-mini")
658660
project_context = os.environ.get("INPUT_PROJECT_CONTEXT", "")
659661
ignore_folders = [folder.strip() for folder in os.environ.get("INPUT_IGNORE_FOLDERS", "build").split(',') if folder.strip()]
660662
else:
@@ -668,7 +670,7 @@ def main() -> None:
668670
help="Enable manual validation for OpenAI returned translations before saving into the XML file")
669671
parser.add_argument("-l", "--log-trace", action="store_true",
670672
help="Log detailed trace information about operations including requests and responses with OpenAI")
671-
parser.add_argument("--openai-model", default="gpt-3.5-turbo",
673+
parser.add_argument("--openai-model", default="gpt-4o-mini",
672674
help="Specify the OpenAI model to use for translation.")
673675
parser.add_argument("--project-context", default="",
674676
help="Specify additional project context to include in translation prompts.")

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ The action supports the following inputs:
9999
| **resources_paths** | Paths to the Android resource directories. Typically includes directories such as `app/src/main/res`, `library/src/main/res`, etc. If not provided, this action will search throughout the entire project folder (which is the default). | `${{ github.workspace }}` | Yes | `./app/src/main/res, ./library/src/main/res, ./feature/src/main/res` | | **resources_paths | **
100100
| **auto_translate** | Automatically translate missing resources. Set to `false` to disable auto-translation. | `"true"` | Yes | `"true"` or `"false"` |
101101
| **log_trace** | Enable detailed logging. Use `"true"` for verbose output. | `"false"` | Yes | `"true"` |
102-
| **openai_model** | Specify the OpenAI model to use for translation. We advise using `gpt-3.5-turbo`. | `"gpt-3.5-turbo"` | Yes | `"gpt-3.5-turbo"`, `"gpt-4o"` |
102+
| **openai_model** | Specify the OpenAI model to use for translation. We advise using `gpt-4o-mini`. | `"gpt-4o-mini"` | Yes | `"gpt-3.5-turbo"`, `"gpt-4o"` |
103103
| **project_context** | Additional project context to include in translation prompts. | `""` | Yes | `"Android launcher application"` |
104104
| **ignore_folders** | Comma-separated list of folder names to ignore during resource scanning (e.g., build). | `"build"` | Yes | `"build,temp,cache"` |
105105

0 commit comments

Comments
 (0)