Last active
September 14, 2019 10:59
Revisions
-
tranghaviet revised this gist
Sep 14, 2019 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ # Add Audio Program type to GoldenDict bash -c "p=$(echo "%GDWORD%" |sed 's/ /+/g'); wget -q -U Mozilla -O - translate.google.com.vn/translate_tts?ie=UTF-8\&q=$p\&tl=en\&client=tw-ob | mpg123 -" -
tranghaviet created this gist
Sep 14, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ <?php // Usage // php -f /path/to/google-goldendict.php "words you want to translate // In GoldenDict go to Dictionaries/Programs, choose "Add..." // name: Google translation // Type: HTML // Command Line: php -f /path/to/google-goldendict.php %GDWORD% $text = $argv[1]; $postdata = http_build_query(['q' => $text]); $opts = [ 'http' => [ 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata, ], ]; $context = stream_context_create($opts); $url = 'http://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=vi&dt=t&ie=UTF-8&oe=UTF-8'; $resultText = file_get_contents($url, false, $context); $resultText = preg_replace('/,+/', ',', $resultText); $results = json_decode($resultText); if (is_array($results) && count($results) > 0) { foreach ($results[0] as $result) { echo str_replace("\n", ' ', $result[0]); } } echo "<hr><a href='https://translate.google.com/#auto/en/$text'>Open in Google Translate</a>";