Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kill request if there are no [more] available translation samples #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions reverso_context_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def get_translation_samples(self, text, target_text=None, source_lang=None, targ
'In order to achieve good consumer protection, international rules are required.')
"""
for page in self._translations_pager(text, target_text, source_lang, target_lang):

for entry in page["list"]:
source_text, translation = entry["s_text"], entry["t_text"]
if cleanup:
Expand Down Expand Up @@ -120,6 +121,10 @@ def _translations_pager(self, text, target_text=None, source_lang=None, target_l
yield contents
page_num += 1

# if the page has no examples, or has ran out of them, stop iterating.
if contents["list"] == []:
break

def _favorites_pager(self, source_lang=None, target_lang=None):
source_lang = source_lang or self._source_lang
target_lang = target_lang or self._target_lang
Expand Down