1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
<?php
/**
* Translator
* Transform Kalkun into mobile dictionary app using gtranslate-api-php <http://code.google.com/p/gtranslate-api-php/>
*
* @author Azhari Harahap <azhari@harahap.us>
* @link http://azhari.harahap.us/2011/04/howto-turn-kalkun-into-awesome-mobile-dictionary-app/
*/
// ------------------------------------------------------------------------
define('GTranslate_path', '/path/to/gtranslate-api-php/GTranslate.php');
define('Kalkun_API_path', '/path/to/kalkun/scripts/cURL/Kalkun_API.php');
$arg_list = $_SERVER['argv'];
$arg_count = count($arg_list);
if ($arg_count > 2)
{
$phone_number = $arg_list[1];
unset($arg_list[0]);
unset($arg_list[1]);
// build the text
$translate_string = implode(' ', $arg_list);
require(GTranslate_path);
try
{
$gt = new Gtranslate;
$gt->setRequestType('curl');
$gt->setLanguageFile('languages.ini');
$translated_string = $gt->indonesian_to_english($translate_string);
// Send translated text by SMS
include_once(Kalkun_API_path);
$config['base_url'] = 'http://localhost/kalkun/index.php/';
$config['session_file'] = '/tmp/cookies.txt';
$config['username'] = 'kalkun';
$config['password'] = 'kalkun';
$config['phone_number'] = $phone_number;
$config['message'] = $translated_string;
$sms = new Kalkun_API($config);
$sms->run();
}
catch (GTranslateException $ge)
{
echo $ge->getMessage();
}
}
|