בWednesday 01 April 2009, נכתב על ידי Arie Skliarouk:
> Hi,
>
> An immigrant from Windows asked me about hebrew-english and
> english-hebrew dictionary for Linux. Quick google search haven't produced
> anything meaningful.
>
> For now they are using http://milon.morfix.co.il/
> but it is relatively slow, requires internet connection, and is not
> integrated into desktop (they want to highligh a word, right-click and
> get a translation).
>
> What are people using?
>
> --
> Arie

Not so good on the UI side, but I use this script to connect to google 
translation service. I am not sure if it is valid to use it like this, so 
use at your own risk.

Use it like this:
$ translate <from lang code> <to lang code>

for example, 'translate en he' to translate from english to hebrew

It should be rather simple to write a graphic interface for this.

--8<---------------cut here---------------start------------->8---
#!/usr/bin/php
<?php

/**
 * Google translate PHP script
 * 
 * Written by Yuval Hager <yu...@avramzon.net>
 * License: GPL
 */

/**
 * Usage:
 * $ translate [slan [tlan]]
 * will translate STDIN from slan (default en) to tlan (default he)
 * You can use this for files too:
 * $ translate he fr < heb.txt
 *
 * Report bugs to yu...@avramzon.net
 */
function wget($url) {
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $data = curl_exec($ch);
  curl_close($ch);
  return $data;
}

function translate ($text, $from, $to) {
  $text = urlencode($text);
  $langs = urlencode("$from|$to");
  
$url="http://www.google.com/translate_t?text=$text&langpair=$langs&ie=utf8&oe=utf8";;
  //print $url . "\n";
  $data = wget($url);
  //print $data . "\n";
  preg_match('@<div id=result_box dir="(ltr|rtl)">(.*?)</div>@', $data, 
$matches);
  $result = $matches[2];
  return str_replace('<br>', "\n", $result) . "\n";
  //var_dump($matches);
}

$from = $argv[1] ? $argv[1] : 'en';
$to = $argv[2] ? $argv[2] : 'he';

print "Type $from text, to translate to $to:\n";
//$text = urlencode($argv[1]);
while ($text = fread(STDIN,8192)) {
  print translate($text, $from, $to);
}


--8<---------------cut here---------------end--------------->8---


-- 
yuval

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il

Reply via email to