Work on Google API v2

This commit is contained in:
Laurent Destailleur 2012-01-23 02:35:17 +01:00
parent 5d5af4cd78
commit 4e13863513
2 changed files with 11 additions and 8 deletions

View File

@ -291,9 +291,11 @@ class autoTranslator
$src_text_to_translate=preg_replace('/'.preg_quote('\n\n').'/',' NNNNN ',$src_text_to_translate);
// Define GET URL v1
$url = "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=".urlencode($src_text_to_translate)."&langpair=".urlencode($lang_pair);
//$url = "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=".urlencode($src_text_to_translate)."&langpair=".urlencode($lang_pair);
// Example: http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=Setup%20area&langpair=en_US|fr_FR
// Define GET URL v2
// Example: "https://www.googleapis.com/language/translate/v2?key=".$this->apikey."&q=".urlencode($src_text_to_translate)."&source=".$src_lang."&target=".$dest_lang
$url = "https://www.googleapis.com/language/translate/v2?key=".$this->apikey."&q=".urlencode($src_text_to_translate)."&source=".urlencode($src_lang)."&target=".urlencode($dest_lang);
// Example: https://www.googleapis.com/language/translate/v2?key=APIKEY&q=Setup%20area&source=en_US&target=fr_FR
// Send request
print "Url to translate: ".$url."\n";

View File

@ -56,8 +56,8 @@ $dir=DOL_DOCUMENT_ROOT."/langs";
// Check parameters
if (! isset($argv[2])) {
print "Usage: ".$script_file." lang_code_src lang_code_dest|all [langfile.lang]\n";
print "Example: ".$script_file." en_US pt_PT\n";
print "Usage: ".$script_file." lang_code_src lang_code_dest|all APIKEY [langfile.lang]\n";
print "Example: ".$script_file." en_US pt_PT 123456\n";
print "Rem: lang_code to use can be found on http://www.google.com/language_tools\n";
exit;
}
@ -65,11 +65,12 @@ if (! isset($argv[2])) {
// Show parameters
print 'Argument 1='.$argv[1]."\n";
print 'Argument 2='.$argv[2]."\n";
print 'Argument 3='.$argv[3]."\n";
$file='';
if (isset($argv[3]))
if (isset($argv[4]))
{
$file=$argv[3];
print 'Argument 3='.$argv[3]."\n";
$file=$argv[4];
print 'Argument 4='.$argv[4]."\n";
}
print 'Files will be generated/updated in directory '.$dir."\n";
@ -89,7 +90,7 @@ if ($argv[2] != 'all')
require_once(DOL_DOCUMENT_ROOT."/../dev/translation/autotranslator.class.php");
$langParser = new autoTranslator($argv[2],$argv[1],$dir,$file,$apikey);
$langParser = new autoTranslator($argv[2],$argv[1],$dir,$file,$argv[3]);
print "***** Finished *****\n";