<commit_before>"""
Translate module.
"""

from .util.decorators import command
import requests
from .util.data import www_headers as headers


@command('translate', category='language')
def translate(bot, nick, chan, arg):
    """ Translate a snippet. Usage: translate <from>-<to> <snippet> """
    args = arg.split()
    langpair = args[0].replace('-', '|').replace('#', '-')
    word = ' '.join(args[1:])
    url = "http://api.mymemory.translated.net/get"
    params = {'q': word, 'langpair': langpair, 'de': '<EMAIL>'}
    response = requests.get(url, headers=headers, params=params)
    data = response.json()
    if 'INVALID TARGET LANGUAGE' in data['responseData']['translatedText']:
        return bot.msg(chan, "%s: Invalid target language." % (nick))
    else:
        bot.msg(chan, "%s: %s" % (nick, data['responseData']['translatedText']))<commit_msg>Finally get rid of that +translate uppercase stuff<commit_after>"""
Translate module.
"""

from .util.decorators import command
import requests
from .util.data import www_headers as headers


@command('translate', category='language')
def translate(bot, nick, chan, arg):
    """ Translate a snippet. Usage: translate <from>-<to> <snippet> """
    args = arg.split()
    langpair = args[0].replace('-', '|').replace('#', '-')
    word = ' '.join(args[1:])
    url = "http://api.mymemory.translated.net/get"
    params = {'q': word, 'langpair': langpair, 'de': '<EMAIL>'}
    response = requests.get(url, headers=headers, params=params)
    data = response.json()
    if 'INVALID TARGET LANGUAGE' in data['responseData']['translatedText']:
        return bot.msg(chan, "%s: Invalid target language. See http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes" % (nick))
    if 'INVALID SOURCE LANGUAGE' in data['responseData']['translatedText']:
        return bot.msg(chan, "%s: Invalid source language. See http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes" % (nick))
    else:
        bot.msg(chan, "%s: %s" % (nick, data['responseData']['translatedText']))
{'fraction_non_alphanumeric': 0.1830776843146957, 'fraction_numerical': 0.005937654626422563, 'mean_word_length': 4.238341968911917, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1316249', 'n_tokens_mistral': 660, 'n_tokens_neox': 637, 'n_words': 163}