svn: /web/doc-editor/trunk/php/ GTranslate.php

[email protected] (Yannick Torres)
Newsgroups php.doc.web
Message-ID <[email protected]>
yannick                                  Sat, 06 Mar 2010 08:58:58 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=295888

Log:
Split the request string to avoide the GoogleTranslation limit to 5000 caracters

Changed paths:
    U   web/doc-editor/trunk/php/GTranslate.php

Modified: web/doc-editor/trunk/php/GTranslate.php
===================================================================
--- web/doc-editor/trunk/php/GTranslate.php	2010-03-06 07:44:42 UTC (rev 295887)
+++ web/doc-editor/trunk/php/GTranslate.php	2010-03-06 08:58:58 UTC (rev 295888)
@@ -58,6 +58,9 @@

 class GTranslate
 {
+
+        private $returnTranslation = '';
+
         /**
         * Google Translate(TM) Api endpoint
         * @access private
@@ -277,6 +280,16 @@
         {
             $languages = Array($langFrom, $langTo);

+            // If the passed string is to large, we try to truncate it and make multi-query
+            if( strlen($string) > 5000 ) {
+
+                $strings = explode('§',wordwrap($string, 4000, '§'));
+
+                for( $i=0; $i < count($strings); $i++ ) {
+                    $this->returnTranslation .= $this->query($languages,$strings[$i]);
+                }
+                return $this->returnTranslation;
+            }
             return $this->query($languages,$string);
         }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.