Skip to content

Commit 6fc3aae

Browse files
committed
Add option accept all.
1 parent 856b203 commit 6fc3aae

File tree

2 files changed

+60
-39
lines changed

2 files changed

+60
-39
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,5 @@ docs/_build/
5353

5454
# PyBuilder
5555
target/
56+
57+
.idea/

honyaku/cli.py

+58-39
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ def patched(*args, **kwargs):
7373
@click.option('--max-words',
7474
default=None, type=click.INT,
7575
help="Maximum number of words in sentence")
76+
@click.option('--accept-all/--no-accept-all',
77+
default=False, help="Automatically accept all translations")
7678
def cli(pofile, source, target, tier, public_key, private_key, sandbox, debug,
77-
limit, comment, tone, min_words, max_words):
79+
limit, comment, tone, min_words, max_words, accept_all):
7880
""" Takes the given pofile and submits its entries to the gengo API for
7981
translation. Translated strings are acquired once they are translated
8082
and stored in the pofile.
@@ -88,6 +90,10 @@ def cli(pofile, source, target, tier, public_key, private_key, sandbox, debug,
8890
8991
honyaku german.po de fr --tier pro
9092
93+
Run with --accept-all to automatically approve all translations:
94+
95+
honyaku german.po de fr --accept-all
96+
9197
"""
9298

9399
# to make sure that the security issue is patched properly, we do that
@@ -131,50 +137,63 @@ def fetch_translations(order_id):
131137
if not is_order_complete(order_id):
132138
reviewable = fetch_order_jobs(order_id)['jobs_reviewable']
133139

134-
columns = shutil.get_terminal_size((80, 20)).columns
135-
single_hr = "-" * columns
136-
double_hr = "=" * columns
137-
138-
for job_id in reviewable:
139-
job = gengo.getTranslationJob(id=job_id)['response']['job']
140-
print(double_hr)
141-
print(job['body_src'])
142-
print(single_hr)
143-
print(job['body_tgt'])
144-
print(single_hr)
145-
146-
answer = None
147-
while answer not in ('a', 'r', 'q'):
148-
149-
answer = input(
150-
"(a)ccept translation, (r)evise it or (q)uit? ")
151-
152-
answer = answer[0]
153-
154-
if answer == 'q':
155-
return
156-
157-
if answer == 'a':
140+
if accept_all:
141+
# Automatically accept all translations
142+
print(f"Auto-accepting {len(reviewable)} translations...")
143+
for job_id in reviewable:
158144
gengo.updateTranslationJob(
159145
id=job_id,
160146
action={
161147
'action': 'approve',
162148
}
163149
)
164-
print("")
165-
continue
166-
167-
if answer == 'r':
168-
comment = input("comment for the translator: ")
169-
gengo.updateTranslationJob(
170-
id=job_id,
171-
action={
172-
'action': 'revise',
173-
'comment': comment
174-
}
175-
)
176-
print("")
177-
continue
150+
print(f"All {len(reviewable)} translations accepted.")
151+
else:
152+
# Interactive review process
153+
columns = shutil.get_terminal_size((80, 20)).columns
154+
single_hr = "-" * columns
155+
double_hr = "=" * columns
156+
157+
for job_id in reviewable:
158+
job = gengo.getTranslationJob(id=job_id)['response']['job']
159+
print(double_hr)
160+
print(job['body_src'])
161+
print(single_hr)
162+
print(job['body_tgt'])
163+
print(single_hr)
164+
165+
answer = None
166+
while answer not in ('a', 'r', 'q'):
167+
168+
answer = input(
169+
"(a)ccept translation, (r)evise it or (q)uit? ")
170+
171+
answer = answer[0]
172+
173+
if answer == 'q':
174+
return
175+
176+
if answer == 'a':
177+
gengo.updateTranslationJob(
178+
id=job_id,
179+
action={
180+
'action': 'approve',
181+
}
182+
)
183+
print("")
184+
continue
185+
186+
if answer == 'r':
187+
comment = input("comment for the translator: ")
188+
gengo.updateTranslationJob(
189+
id=job_id,
190+
action={
191+
'action': 'revise',
192+
'comment': comment
193+
}
194+
)
195+
print("")
196+
continue
178197

179198
if not is_order_complete(order_id):
180199
print("Order is not yet complete")

0 commit comments

Comments
 (0)