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

Fix translation code for new googletrans(>=4.0.0rc1) #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
13 changes: 9 additions & 4 deletions potranslator/potranslator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from copy import deepcopy
from datetime import datetime
from codecs import open
from time import sleep
import sys
import click

Expand Down Expand Up @@ -40,7 +41,7 @@ def __init__(self, pot_dir=None, locale_dir=None):
self.translator = Translator()
return

def translate(self, file_name, target_lang='auto', src_lang='auto', encoding='utf-8', auto_save=False, compiled=False):
def translate(self, file_name, target_lang='auto', src_lang='auto', encoding='utf-8', auto_save=False, compiled=False, waitfor=3.0):
"""
Translates the given po file in the specified target language.

Expand Down Expand Up @@ -71,9 +72,13 @@ def translate(self, file_name, target_lang='auto', src_lang='auto', encoding='ut
if untranslated:
updated = True
try:
translations = self.translator.translate([elmt.msgid for elmt in untranslated], src=src_lang, dest=target_lang)
for entry, translation in zip(untranslated, translations):
entry.msgstr = translation.text
print('{1}: translation start to {0} from {2}'.format(SUPPORTED_LANGUAGES[target_lang], file_name, src_lang))
total_entry = len(untranslated)
for i, entry in enumerate(untranslated):
entry.msgstr = self.translator.translate(entry.msgid, src=src_lang, dest=target_lang).text
print(_('{1}: {0} ({2}/{3}) translated "{4}" -> "{5}"').format(SUPPORTED_LANGUAGES[target_lang], file_name, i, total_entry, entry.msgid, entry.msgstr))
if waitfor > 0:
sleep(waitfor)
po.metadata['Translated-By'] = 'potranslator {0}'.format(__version__)
po.metadata['Last-Translator'] = 'potranslator {0}'.format(__version__)
po.metadata['Language'] = target_lang
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
googletrans==2.3.0
googletrans==4.0.0rc1
polib==1.1.0
Click>=6.0
path.py==11.5.0
Expand Down