Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def main():
version_warning()
args = cli()
if args.gt_list:
languages_list()
return
lang = args.up or args.gt
if not lang:
main_gen(args.only_changes, args.comments)
return
if lang not in googletrans.LANGUAGES:
print('Wrong lang code {}, use: {}'.format(
lang, ', '.join([key for key in googletrans.LANGUAGES if key != 'ru'])))
exit(1)
if lang == 'ru':
print('Don\'t use ru.')
exit(1)
if args.up:
file_path = os.path.join(LNG_DIR, '{}.py'.format(lang))
main_trans(file_path)
else:
file_path = os.path.join(LNG_DIR, 'gt_{}.py'.format(lang))
main_trans(file_path, args.gt, args.delay, args.proxy, args.no_gt, args.full)
if not (
len(emoji) == 2
and ord(emoji[0]) in INDICATOR_RANGE
and ord(emoji[1]) in INDICATOR_RANGE
):
return
code = LETTERS[INDICATOR_RANGE.index(ord(emoji[0]))] \
+ LETTERS[INDICATOR_RANGE.index(ord(emoji[1]))]
erroridx = 0
while 1:
lang = LANGS[code][erroridx]
if lang in LANGUAGES:
break
if '-' in lang:
lang = lang.split('-', 1)[0]
if lang in LANGUAGES:
break
erroridx += 1
guild = self.bot.get_guild(event.guild_id)
channel = self.bot.get_channel(event.channel_id)
user = self.bot.get_user(event.user_id)
if channel is None:
await user.create_dm()
channel = user.dm_channel
message = await channel.fetch_message(event.message_id)
ctx = DummyCtx(
guild=guild,
channel=channel,
message=message,
author=user
)
text = message.clean_content
def google_translator(lang, delay, proxies, data: dict, chunk=30) -> dict:
def progress(percent, eta):
print('[{}%] ETA: {} sec, Elapse: {} sec.{}'.format(
round(percent, 1), int(eta), int(time.time() - start_time), ' ' * 20), end='', flush=True
)
print('Translate {} phrases from {} to {}'.format(
len(data), googletrans.LANGUAGES['ru'], googletrans.LANGUAGES[lang]
))
print()
chunks = [x for x in data.keys()]
chunks = [chunks[i:i + chunk] for i in range(0, len(chunks), chunk)]
full = len(chunks)
count, drift = 0, 0
start_time = time.time()
translator = googletrans.Translator(proxies=proxies)
for part in chunks:
print(end='\r', flush=True)
progress((100 / full) * count, (full - count) * (delay + drift))
drift = time.time()
for trans in translator.translate(text=part, src='ru', dest=lang):
data[trans.origin] = _fix_gt(trans.origin, trans.text)
drift = time.time() - drift
async def translate(self, ctx, *, message: commands.clean_content):
"""Translates a message to English using Google translate."""
loop = self.bot.loop
try:
ret = await loop.run_in_executor(None, self.trans.translate, message)
except Exception as e:
return await ctx.send(f'An error occurred: {e.__class__.__name__}: {e}')
embed = discord.Embed(title='Translated', colour=0x4284F3)
src = googletrans.LANGUAGES.get(ret.src, '(auto-detected)').title()
dest = googletrans.LANGUAGES.get(ret.dest, 'Unknown').title()
embed.add_field(name=f'From {src}', value=ret.origin, inline=False)
embed.add_field(name=f'To {dest}', value=ret.text, inline=False)
await ctx.send(embed=embed)
async def translate(self, ctx, *, message: commands.clean_content):
"""Translates a message to English using Google translate."""
loop = self.bot.loop
try:
ret = await loop.run_in_executor(None, self.trans.translate, message)
except Exception as e:
return await ctx.send(f'An error occurred: {e.__class__.__name__}: {e}')
embed = discord.Embed(title='Translated', colour=0x4284F3)
src = googletrans.LANGUAGES.get(ret.src, '(auto-detected)').title()
dest = googletrans.LANGUAGES.get(ret.dest, 'Unknown').title()
embed.add_field(name=f'From {src}', value=ret.origin, inline=False)
embed.add_field(name=f'To {dest}', value=ret.text, inline=False)
await ctx.send(embed=embed)
def languages_list():
print(' CODE LANGUAGE')
border(32)
[print(' {:7}- {:}'.format(k, v)) for k, v in googletrans.LANGUAGES.items()]
border(32)
def __init__(self, parent=None):
super(Window, self).__init__(parent)
languages = googletrans.LANGUAGES.copy()
languages['zh-cn'] = '中文(简体)'
languages['zh-tw'] = '中文(繁体)'
self.langcodes = dict(map(reversed, languages.items()))
self.langlist = [k.capitalize() for k in self.langcodes.keys()]
self.browseButton = self.createButton("&浏览...", self.browse)
self.transButton = self.createButton("&翻译", self.translate)
self.lang_srcComboBox = self.createComboBox()
srcIndex = self.langlist.index('English')
self.lang_srcComboBox.setCurrentIndex(srcIndex)
self.lang_dstComboBox = self.createComboBox()
dstIndex = self.langlist.index('中文(简体)')
self.lang_dstComboBox.setCurrentIndex(dstIndex)
self.fileComboBox = self.createComboBox('file')
def translate(self, event):
src = self.translator.detect(self.src).lang
if self.is_dete:
self.mainFrame.fromchoice.SetSelection(self.mainFrame.fromchoice.FindString(LANGUAGES[src.lower()]))
else:
src = self.getSrcLang()
dest = self.getTgtLang()
if self.result != self.src:
self.setResult(self.translator.translate(self.src, src=src, dest=dest).text)
self.valid = True
else:
self.valid = False
def translate(self, event):
src = self.translator.detect(self.src).lang
if self.is_dete:
self.mainFrame.fromchoice.SetSelection(self.mainFrame.fromchoice.FindString(LANGUAGES[src.lower()]))
else:
src = self.getSrcLang()
dest = self.getTgtLang()
if self.result != self.src:
self.setResult(self.translator.translate(self.src, src=src, dest=dest).text)
self.valid = True
else:
self.valid = False