hi Muthu,

great job! i will abuse of it for the missing translations :)
gj.

On 2010-09-14 7:18.MD, Ap.Muthu wrote:
> The info was given to illustrate a point. If translation was needed, then we
> could use it for a one time grab to capture the translated info and store it
> in a table / csv file like all the others. It was never intended to be used
> in a fully online manner.
>
> Managed to translate 5000 records in 10 minutes and then Google cut the IP
> off for presumably excessive use.
> Local 512 Kbps line manages 200 records in 150 secs.
>
> Used a small progress bar script to do the job.
>
> Here is the script that may have some other use:
>
> =================
> // Copy the ops301_de.csv to ops301_en.csv in the same folder as this script
> // Usage 1: http://domain.com/scriptname.php?s=1201&t=1500&d=1
> // This will display the original lineand the translated line - debug mode -
> for lines 1201 to 1500
> // Usage 2: http://domain.com/scriptname.php?s=1201&t=1500
> // This will populate a new file ops301_out_en.csv with the contents of
> ops301_en.csv, replacing the lines 1201 to 1500 with their translated
> equivalent.
>
> // utf-8 is required to display characters properly
> header('Content-Type: text/html; charset=utf-8');
>
> require_once('google.translator.php');
>
> $stline = (isset($_REQUEST['s']) ? ($_REQUEST['s']-1) : 0);
> $toline = (isset($_REQUEST['t']) ? ($_REQUEST['t']+0) : 0);
> $debug = isset($_REQUEST['d']);
> $frlang = 'de';
> $tolang = 'en';
>
> $filename = "ops301_$tolang.csv";
> $outfile = "ops301_out_$tolang.csv";
>
> $handle = fopen($filename, "rb");
> $contents = fread($handle, filesize($filename));
> fclose($handle);
>
> $contents = str_replace(CHR(13), '', $contents); // strip the carriage
> returns
> $mylines = explode(CHR(10), $contents);
>
> $numlines = $toline-$stline+1;
> $pcperline = 100.00 / $numlines;
> $pc = 0.00;
>
> create_progress();
> echo '<br><br><br><br>';
>
> for ($i = $stline; $i<  $toline; $i++) {
>    $myline = FALSE;
>    $myline = explode (";", $mylines[$i]);
>
>
>    // Translatable text is in Fields 1, 2, 3 and 4 only
>    for ($j = 1; $j<  5; $j++) {
>      $mylinefld = trim($myline[$j]);
>      if ( (strlen($mylinefld)>  0)&&  (!($mylinefld == ': N.n.bez.')) ){
>        $mylinefld = str_replace('"', '', $mylinefld); // Strip the double
> quotes for translation
>        $mylinefld = str_replace('<br>', ' ### ', $mylinefld); // Strip the
> html BR for translation
>
>        $mylinefld = '"' . Google_Translate_API::translate($mylinefld,
> $frlang, $tolang) . '"'; // put back the double quotes
>
>     $mylinefld = str_replace(' # # # ', '<br>', $mylinefld); // Put back the
> html BR (extra spaces for UTF8) after translation
>
>   }
>      $myline[$j] = str_replace(': Nnbez.', ': N.n.bez.', $mylinefld); // just
> know that it is needed to work. N.n.bez. ->  Not Specified Further
>    }
>    if ($debug) {
>   echo $mylines[$i];   // Show Original
>   echo  CHR(13) . CHR(10) . '<br>'; // put back the carriage returns
>    }
>    $mylines[$i] = implode(';', $myline);
>    if ($debug) {
>   echo $mylines[$i];   // Show Translation
>   echo  CHR(13) . CHR(10) . '<br>' .'<br>'; // put back the carriage returns
>    }
>    $pc += $pcperline;
>    $pc = round($pc,2);
>    update_progress($pc);
> }
>
>
> if (!($debug)) {
>   $fp = fopen($outfile, 'wb');
>   $cnt = count($mylines);
>   for ($i = 0; $i<  $cnt; $i++) {
>    if (strlen(trim($mylines[$i]))>  0) {
>     fwrite($fp, $mylines[$i]);
>     fwrite($fp, CHR(13) . CHR(10) ); // put back the carriage returns
>    }
>   }
>   fclose($fp);
> }
>
> function progressBar($percentage) {
>   print "<div id=\"progress-bar\" class=\"all-rounded\">\n";
>   print "<div id=\"progress-bar-percentage\" class=\"all-rounded\"
> style=\"width: $percentage%\">";
>    if ($percentage>  5) {print "$percentage%&nbsp;&nbsp;&nbsp;";} else
> {print "<div class=\"spacer\">&nbsp;</div>";}
>   print "</div></div>";
> }
>
> function create_progress() {
>    // First create our basic CSS that will control
>    // the look of this bar:
>    echo "
> <style>
> #text {
>    position: absolute;
>    top: 10px;
>    left: 20%;
>    margin: 0px 0px 0px -150px;
>    font-size: 18px;
>    text-align: center;
>    width: 400px;
> }
>    #barbox_a {
>    position: absolute;
>    top: 40px;
>    left: 20%;
>    margin: 0px 0px 0px -160px;
>    width: 404px;
>    height: 24px;
>    background-color: black;
> }
> .per {
>    position: absolute;
>    top: 40px;
>    font-size: 18px;
>    left: 20%;
>    margin: 1px 0px 0px 250px;
>    background-color: #FFFFFF;
> }
>
> .bar {
>    position: absolute;
>    top: 42px;
>    left: 20%;
>    margin: 0px 0px 0px -158px;
>    width: 0px;
>    height: 20px;
>    background-color: #0099FF;
> }
>
> .blank {
>    background-color: white;
>    width: 400px;
> }
> </style>
> ";
>
>    // Now output the basic, initial, XHTML that
>    // will be overwritten later:
>    echo "
> <div id='text'>Script Progress</div>
> <div id='barbox_a'></div>
> <div class='bar blank'></div>
> <div class='per'>0%</div>
> ";
>
>    // Ensure that this gets to the screen
>    // immediately:
>    flush();
> }
>
> function update_progress($percent) {
>    // First let's recreate the percent with
>    // the new one:
>    echo "<div class='per'>{$percent}
>      %</div>\n";
>
>    // Now, output a new 'bar', forcing its width
>    // to 4 times the percent, since we have
>    // defined the percent bar to be at
>    // 400 pixels wide.
>    echo "<div class='bar' style='width: ",
>      $percent * 4, "px'></div>\n";
>
>    // Now, again, force this to be
>    // immediately displayed:
>    flush();
> }
>
> =================
>
>
> Regards,
> Ap.Muthu
>
>> I don't think that we have to translate OPS 301. For all other views on
>> translation we might could think about that option to use remote but as
>> far I have read (quick cross read the google language API) it would need
>> permanent access to Google's remote servers.
>> Care2x should be placed on a server what do not have direct internet
>> access based on the matter of trust. We store medical and confidential
>> data and for that we should recommend conservative and strict proceudues
>> for it and not have internet access in our installation requirement
>> lists.
>>
>> I would recommend for care2x as well as other databases for ERP and CRM
>> in production use to place these server in an network isolated way,
>> called "Demilitarized Zone" (DMZ):
>> http://en.wikipedia.org/wiki/Demilitarized_zone_%28computing%29
>>
>> Well, we cannot classify the internet as trusted network and so we might
>> not able to use it.
>>
>> Or had I an misinterpretation of the API? Does it work also offline?
>>
>> Robert
>>
>>
>> Am Dienstag, den 14.09.2010, 10:19 +0530 schrieb Ap.Muthu:
>>> While working on the easiest way to translate the OPS301 CSV files so
>>> that
>>> any language can be added on the fly from the original German file, I
>>> checked out the Google Translate APIs and here are the Links:
>>>
>>> Two Wrappers:
>>> 1. Official: http://code.google.com/p/php-language-api/
>>> 2. Third-Party: http://code.google.com/p/gtranslate-api-php/
>>>
>>> Here is some sample code:
>>>
>>> ======
>>>
>>> require_once("GTranslate.php");
>>> try{
>>>   $gt = new Gtranslate;
>>>         echo "Translating [Hello World] from English to German =>
>>> ".$gt->english_to_german("hello world")."<br/>";
>>>         echo "Translating [Ciao mondo] Italian to English =>
>>> ".$gt->it_to_en("Ciao mondo")."<br/>";
>>>   } catch (GTranslateException $ge)
>>>   {
>>>   echo $ge->getMessage();
>>> }
>>>
>>> // ====
>>>
>>> echo "<br>";
>>> echo "<br>";
>>>
>>> // ====
>>>
>>> // utf-8 is required to display characters properly
>>> header('Content-Type: text/html; charset=utf-8');
>>>
>>> require_once('google.translator.php');
>>>
>>> // translate apple from english to portuguese
>>> $str = Google_Translate_API::translate('Apple', 'pt', 'en');
>>>
>>> // view the translated string
>>> var_dump($str);
>>>
>>>
>>> ======
>>>
>>> Regards,
>>> Ap.Muthu
>
>
> ------------------------------------------------------------------------------
> Start uncovering the many advantages of virtual appliances
> and start using them to simplify application deployment and
> accelerate your shift to cloud computing.
> http://p.sf.net/sfu/novell-sfdev2dev
> _______________________________________________
> Care2002-developers mailing list
> Care2002-developers@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/care2002-developers

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Care2002-developers mailing list
Care2002-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/care2002-developers

Reply via email to