Skip to content

Commit 179e0b1

Browse files
committed
Fix retries
1 parent ea8a72f commit 179e0b1

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/i18n/tasks/translators/openai_translator.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)