@@ -24,7 +24,7 @@ final class OpenAITranslator implements Translator
2424
2525 public function __construct (
2626 string $ apiKey ,
27- private readonly string $ model = 'gpt-4o ' ,
27+ private readonly string $ model = 'gpt-4 ' ,
2828 ) {
2929 $ this ->client = (new Factory ())->withApiKey ($ apiKey )->make ();
3030 $ this ->languageCodeService = new LanguageCodeService ();
@@ -82,7 +82,7 @@ public function translate(array $groups, string $targetLanguage, ?string $source
8282 throw new RuntimeException ('Invalid JSON in response ' );
8383 }
8484
85- // Verify translations are valid
85+ // Verify that translations are different from the original text
8686 foreach ($ translations as $ key => $ translation ) {
8787 if (! isset ($ strings [$ key ])) {
8888 throw new RuntimeException (sprintf (
@@ -95,6 +95,10 @@ public function translate(array $groups, string $targetLanguage, ?string $source
9595 if (! is_string ($ translation )) {
9696 throw new RuntimeException ("Invalid translation for key ' {$ key }': expected string, got " .gettype ($ translation ));
9797 }
98+
99+ if (mb_strtolower ($ translation ) === mb_strtolower ($ strings [$ key ]['text ' ])) {
100+ throw new RuntimeException ("Translation for ' {$ key }' is the same as the original text " );
101+ }
98102 }
99103
100104 // Verify all strings are translated
@@ -164,12 +168,13 @@ private function getSystemPrompt(): string
164168Your task is to translate text while preserving meaning and context.
165169
166170Important rules to follow:
167- 1. Translate the text to the target language, keeping the original text if it's already appropriate in the target language
171+ 1. Always translate the text to the target language, never return it unchanged
1681722. Preserve the meaning and context of each string
1691733. Use appropriate translations based on context
1701744. Return ONLY a valid JSON object with translations, nothing else
1711755. Each key in the JSON must be exactly as provided in the input
172- 6. Your response must be a valid JSON object, starting with { and ending with }
176+ 6. Never return the original text unchanged
177+ 7. Your response must be a valid JSON object, starting with { and ending with }
173178
174179Example request:
175180```
0 commit comments