Migrating from Windows to Linux: missing hebrew-english dictionary
Yuval Hager
yuval at avramzon.net
Sat Apr 4 08:37:13 IDT 2009
ב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 <yuval at 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 yuval at 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://mailman.cs.huji.ac.il/pipermail/linux-il/attachments/20090404/66fa2844/attachment.bin>
More information about the Linux-il
mailing list