<commit_before>require 'cgi'
require_relative '../utils/webpage'


class Translator
  include Cinch::Plugin

  # cs en "dog"? / cs to en "dog"? / "dog"?
  match /(?:(\w{2,5}) +(?:to)? *(\w{2,5}) +)?"(.+)"\?/, use_prefix: false

  # en to cz dog
  match /(\w{2,5}) +to +(\w{2,5}) +(.+)/, use_prefix: false

  def execute(m, lang_from, lang_to, text)
    m.reply( translate(text, lang_from, lang_to), true)
  end

  def translate(text, from, to)
    from = "auto" if from.nil?
    to = "cs" if to.nil? || to == "cz"

    url =  "http://translate.google.com/translate_a/t?client=t&hl=cs&sl=#{from}&tl=#{to}"
    url << "&multires=1&otf=1&ssel=0&tsel=0&uptl=en&sc=1&text=#{CGI.escape(text)}"<commit_msg>Translator: short version: 2..5 -> 2<commit_after>require 'cgi'
require_relative '../utils/webpage'


class Translator
  include Cinch::Plugin

  # cs en "dog"? / cs to en "dog"? / "dog"?
  match /(?:(\w{2}) +(?:to)? *(\w{2}) +)?"(.+)"\?/, use_prefix: false

  # en to cz dog
  match /(\w{2}) +to +(\w{2}) +(.+)/, use_prefix: false

  def execute(m, lang_from, lang_to, text)
    m.reply( translate(text, lang_from, lang_to), true)
  end

  def translate(text, from, to)
    from = "auto" if from.nil?
    to = "cs" if to.nil? || to == "cz"

    url =  "http://translate.google.com/translate_a/t?client=t&hl=cs&sl=#{from}&tl=#{to}"
    url << "&multires=1&otf=1&ssel=0&tsel=0&uptl=en&sc=1&text=#{CGI.escape(text)}"
{'fraction_non_alphanumeric': 0.23779193205944799, 'fraction_numerical': 0.017692852087756547, 'mean_word_length': 3.7932203389830508, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6573672', 'n_tokens_mistral': 614, 'n_tokens_neox': 591, 'n_words': 125}