@@ -95,12 +95,12 @@ def translate_batch(batch, from, to, retry_count = 0)
95
95
96
96
if result . size != batch . size
97
97
if retry_count < RETRIES
98
- translate_batch ( batch , from , to , retry_count )
98
+ result = translate_batch ( batch , from , to , retry_count + 1 )
99
99
elsif retry_count == RETRIES
100
- # Try each string individually
101
- batch . each do |string |
102
- translate_batch ( [ string ] , from , to , RETRIES + 1 )
103
- end
100
+ # Try each string individually once
101
+ result = batch . each_with_object ( [ ] ) do |string , array |
102
+ array << translate_batch ( [ string ] , from , to , RETRIES + 1 )
103
+ end . flatten
104
104
else
105
105
error = I18n . t ( 'i18n_tasks.openai_translate.errors.invalid_size' , expected : batch . size , actual : result . size )
106
106
fail ::I18n ::Tasks ::CommandError , error
@@ -110,7 +110,7 @@ def translate_batch(batch, from, to, retry_count = 0)
110
110
result
111
111
rescue JSON ::ParserError
112
112
if retry_count < RETRIES
113
- translate_batch ( [ string ] , from , to , retry_count + 1 )
113
+ translate_batch ( batch , from , to , retry_count + 1 )
114
114
else
115
115
raise ::I18n ::Tasks ::CommandError , I18n . t ( 'i18n_tasks.openai_translate.errors.invalid_json' )
116
116
end
0 commit comments