@@ -95,12 +95,12 @@ def translate_batch(batch, from, to, retry_count = 0)
9595
9696 if result . size != batch . size
9797 if retry_count < RETRIES
98- translate_batch ( batch , from , to , retry_count )
98+ result = translate_batch ( batch , from , to , retry_count + 1 )
9999 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
104104 else
105105 error = I18n . t ( 'i18n_tasks.openai_translate.errors.invalid_size' , expected : batch . size , actual : result . size )
106106 fail ::I18n ::Tasks ::CommandError , error
@@ -110,7 +110,7 @@ def translate_batch(batch, from, to, retry_count = 0)
110110 result
111111 rescue JSON ::ParserError
112112 if retry_count < RETRIES
113- translate_batch ( [ string ] , from , to , retry_count + 1 )
113+ translate_batch ( batch , from , to , retry_count + 1 )
114114 else
115115 raise ::I18n ::Tasks ::CommandError , I18n . t ( 'i18n_tasks.openai_translate.errors.invalid_json' )
116116 end
0 commit comments