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);
}