vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Modification Graveyard (https://vborg.vbsupport.ru/forumdisplay.php?f=224)
-   -   Miscellaneous Hacks - vB Global Translator - Multiply your indexed pages & put search traffic on autopilot (https://vborg.vbsupport.ru/showthread.php?t=217329)

vivoperdio 07-05-2009 12:36 AM

Could you please add Indonesian Translation ?

Thank you.

NLP-er 07-05-2009 12:38 AM

Hello. Just worked out for you another data base update which will made it without data duplication and also faster :)

So really on one table still you can have duplicated data, because of mysql unique limitations I didn't set it in wt_cache, but this table has less data than other updated tables.

Also collate was changed - believe it works faster when makes collation by binary values, that by some additional rules like in previous DB.

To have faster DB without data duplication You have to.

For new installations
Here is new DB:
Code:

CREATE TABLE wt_cache (
id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
tl VARCHAR(10),
originaltext VARCHAR(65000),
translated TEXT,
INDEX(originaltext(323), tl)
) ENGINE = MYISAM, CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE wt_cache_medium (
id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
tl VARCHAR(10),
originaltext VARCHAR(255),
translated VARCHAR(1000),
UNIQUE (originaltext, tl)
) ENGINE = MYISAM, CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE wt_cache_short (
id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
tl VARCHAR(10),
originaltext VARCHAR(50),
translated VARCHAR(255),
UNIQUE (originaltext, tl)
) ENGINE = MYISAM, CHARACTER SET utf8 COLLATE utf8_bin;

Also change code in translate.php
this one:
Code:

/* Check cache for translation */
if ($enablecache) {
  $sql=null;
  $length = strlen($text);
  if ($length<=50) {
    $sql = mysql_query("SELECT translated FROM wt_cache_short WHERE originaltext='".addslashes($text)."' AND tl='".addslashes($tl)."' LIMIT 1"); 
  } else if ($length > 255) {
    $sql = mysql_query("SELECT translated FROM wt_cache WHERE originaltext='".addslashes($text)."' AND tl='".addslashes($tl)."' LIMIT 1");
  } else {
    $sql = mysql_query("SELECT translated FROM wt_cache_medium WHERE originaltext='".addslashes($text)."' AND tl='".addslashes($tl)."' LIMIT 1");
  }
 
        while($t = mysql_fetch_array($sql)) {
                return $lsto.$t['translated'].$rsto;
        }
}
/* -- if not found, proceed with Google Translate */

To this one:
Code:

/* Check cache for translation */
if ($enablecache) {
  $sql=null;
  $length = strlen($text);

  if ($length<=50) {
    $sql = mysql_query("SELECT translated FROM wt_cache_short WHERE originaltext='".addslashes($text)."' AND tl='".addslashes($tl)."'") or die('Query to short cache failed: ' . mysql_error());
  } else if ($length > 255) {
    $sql = mysql_query("SELECT translated FROM wt_cache WHERE originaltext='".addslashes($text)."' AND tl='".addslashes($tl)."' LIMIT 1") or die('Query to normal cache failed: ' . mysql_error());
  } else {
    $sql = mysql_query("SELECT translated FROM wt_cache_medium WHERE originaltext='".addslashes($text)."' AND tl='".addslashes($tl)."'") or die('Query to medium cache failed: ' . mysql_error());
  }
 
        while($t = mysql_fetch_array($sql)) {
                return $lsto.$t['translated'].$rsto;
        }
}
/* -- if not found, proceed with Google Translate */

And change this one:
Code:

////////////////////////////////////////////////////
if ($enablecache) {
mysql_connect ($mysqlserver, $dbusername, $dbpassword);
mysql_select_db ($dbname);
mysql_set_charset('utf8');
}
////////////////////////////////////////////////////

To this one (less white screns):
Code:

////////////////////////////////////////////////////
if ($enablecache) {
  establishConnection();
}


function establishConnection() {
  global $dbusername, $dbpassword, $mysqlserver, $dbname;
  mysql_connect ($mysqlserver, $dbusername, $dbpassword) or die('Could not connect: ' . mysql_error());
  mysql_select_db ($dbname) or die('Could not select database');
  mysql_set_charset('utf8');
}
////////////////////////////////////////////////////

And last change. This one:
Code:

/* Save to cache */
if ($enablecache && (strlen($ttext)>0)) {
  $length = strlen($text);
  if ($length<=50) {
    mysql_query("INSERT INTO wt_cache_short SET tl='".addslashes($tl)."', originaltext='".addslashes($text)."', translated='".addslashes(trim($ttext))."'");
  } else if ($length > 255) {
    mysql_query("INSERT INTO wt_cache SET tl='".addslashes($tl)."', originaltext='".addslashes($text)."', translated='".addslashes(trim($ttext))."'");
  } else {
    mysql_query("INSERT INTO wt_cache_medium SET tl='".addslashes($tl)."', originaltext='".addslashes($text)."', translated='".addslashes(trim($ttext))."'");
  }
}
/* -- */

To this one:
Code:

/* Save to cache */
if ($enablecache && (strlen($ttext)>0)) {
  $length = strlen($text);

  if (!mysql_ping()) {
    mysql_close();
    establishConnection();
  }
 
  if ($length<=50) {
    mysql_query("INSERT IGNORE INTO wt_cache_short SET tl='".addslashes($tl)."', originaltext='".addslashes($text)."', translated='".addslashes(trim($ttext))."'") or die('Insert to short cache failed: ' . mysql_error());
  } else if ($length > 255) {
    mysql_query("INSERT INTO wt_cache SET tl='".addslashes($tl)."', originaltext='".addslashes($text)."', translated='".addslashes(trim($ttext))."'") or die('Insert to normal cache failed: ' . mysql_error());
  } else {
    mysql_query("INSERT IGNORE INTO wt_cache_medium SET tl='".addslashes($tl)."', originaltext='".addslashes($text)."', translated='".addslashes(trim($ttext))."'") or die('Insert to medium cache failed: ' . mysql_error());
  }
}
/* -- */

So whole new translate.php is:
Code:

<?php
////////////////////////////////////////////////////
// Global Translator API
////////////////////////////////////////////////////

global $enablesession, $enablecache, $originalEncoding, $fl;
global $dbusername, $dbpassword, $mysqlserver, $dbname;

////////////////////////////////////////////////////
//        SETTINGS
////////////////////////////////////////////////////
$enablesession = false; //ignore
$enablecache = true; //true - enable cache setting, false - disable cache setting
$originalEncoding = 'iso-8859-1'; //refer to your forum source code for your base encoding
$fl = 'en'; //current language (original) - refer table for language variables

$dbusername = "SET_IT";
$dbpassword = "SET_IT";
$mysqlserver = "localhost";
$dbname = "SET_IT";

////////////////////////////////////////////////////

if ($enablesession) {
        @session_name("iPWTLang");
        @session_start();
}


set_time_limit(0);


////////////////////////////////////////////////////
if ($enablecache) {
  establishConnection();
}


function establishConnection() {
  global $dbusername, $dbpassword, $mysqlserver, $dbname;
  mysql_connect ($mysqlserver, $dbusername, $dbpassword) or die('Could not connect: ' . mysql_error());
  mysql_select_db ($dbname) or die('Could not select database');
  mysql_set_charset('utf8');
}
////////////////////////////////////////////////////

function api_strip ($dt) { $dt = str_replace("\\\\", '\\', $dt); return ($dt); }

function emodfix ($dt) { $dt = str_replace('\"', '"', $dt); return ($dt); }

function remove_tags ($html) {
/* Remove reserved triple tags in html */
return preg_replace ("|<<<([^><]*)>>>|e", "emodfix('\\1')", $html);
}

function add_tags ($buffer) {
/* Inject triple tags to html to preserve html content from translation using ob_start */
return preg_replace("/(^|>\/?)([^><]*)($|\/?<)/e",
            "emodfix('\\1').'<<<'.emodfix('\\2').'>>>'.emodfix('\\3')",
            $buffer);
}

function getServerLoad($windows=false)
{
//MY CODE TO DISABLE SERVER LOAD CHEcKING
  return 1;
//END

    $os = strtolower(PHP_OS);
    if (strpos($os, "win") === false) {
        if (file_exists("/proc/loadavg")) {
            $data = file_get_contents("/proc/loadavg");
            $load = explode(' ', $data);
            return $load[0];

        } elseif (function_exists("shell_exec")) {

            $load = explode(' ', `uptime`);
            return $load[count($load)-1];

        } else {

            return false;
        }

    } elseif($windows) {

        if(class_exists("COM")) {
            $wmi = new COM("WinMgmts:\\\\.");
            $cpus = $wmi->InstancesOf("Win32_Processor");

            $cpuload = 0;
            $i = 0;

            if(version_compare('4.50.0', PHP_VERSION) == 1) {
                // PHP 4
                while ($cpu = $cpus->Next()) {
                    $cpuload += $cpu->LoadPercentage;
                    $i++;
                }

            } else {

                // PHP 5
                foreach ( $cpus as $cpu ) {
                    $cpuload += $cpu->LoadPercentage;
                    $i++;
                }
            }

            $cpuload = round($cpuload / $i, 2);
            return "$cpuload%";

        } else {

            return false;
        }
    }
}

function translate($text, $fl, $tl){
if (trim($text) == null) return $text; //skip translation if string empty

/* Retain left and right spaces after translation */
$lsto = substr($text, 0, strlen($text) - strlen(ltrim($text)));
$rsto = substr($text, strlen(rtrim($text)), strlen($text) - strlen(rtrim($text)));
/* -- */

/* Declare global */
global $enablecache,$overloadval,$disinterval;
if(floatval(getServerLoad()) >= 1.5)    // Numeral = server load on which to crash
{

    // Write current time to file.
    $fp = fopen("overloadcache.txt","w");
    fwrite($fp, time() . "");
    fclose($fp);


  if($nfh= @fopen("overloadcache.txt","r"))
  {
      $overloadtime = fgets($nfh);
      if($overloadtime > time()-30)  // Numeral = # seconds after overload not to cache!
      {
          $enablecache = false;
      }
      fclose($nfh);
  }
}

/* Check for server overloads  (modification by DeViAnThans3)*/
global $originalEncoding;
if ($originalEncoding != 'utf-8') {
  $text = iconv($originalEncoding, 'utf-8', trim($text));
} else {
  $text = trim($text);
}

/* Check cache for translation */
if ($enablecache) {
  $sql=null;
  $length = strlen($text);
/*
  if (!mysql_ping()) {
    mysql_close();
    establishConnection();
  }
*/ 
  if ($length<=50) {
    $sql = mysql_query("SELECT translated FROM wt_cache_short WHERE originaltext='".addslashes($text)."' AND tl='".addslashes($tl)."'") or die('Query to short cache failed: ' . mysql_error());
  } else if ($length > 255) {
    $sql = mysql_query("SELECT translated FROM wt_cache WHERE originaltext='".addslashes($text)."' AND tl='".addslashes($tl)."' LIMIT 1") or die('Query to normal cache failed: ' . mysql_error());
  } else {
    $sql = mysql_query("SELECT translated FROM wt_cache_medium WHERE originaltext='".addslashes($text)."' AND tl='".addslashes($tl)."'") or die('Query to medium cache failed: ' . mysql_error());
  }
 
        while($t = mysql_fetch_array($sql)) {
                return $lsto.$t['translated'].$rsto;
        }
}
/* -- if not found, proceed with Google Translate */

/* -Establish cURL connection to Google Translate API server- */
$ch = @curl_init();
//@curl_setopt($ch, CURLOPT_URL, "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&langpair=".urlencode($fl.'|'.$tl)."&q=".urlencode($text));

@curl_setopt($ch, CURLOPT_URL, "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&langpair=".urlencode($fl.'|'.$tl)."&q=".urlencode($text));

//$postParams = "v=1.0&langpair=".$fl.'|'.$tl."&q=".iconv('iso-8859-2', 'utf-8', $text);
//@curl_setopt($ch, CURLOPT_URL, "http://ajax.googleapis.com/ajax/services/language/translate");
//@curl_setopt ($Curl_Session, CURLOPT_POST, 1);
//@curl_setopt ($Curl_Session, CURLOPT_POSTFIELDS, $postParams);

@curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)");
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$in = @curl_exec ($ch);
/* -End connection- */

preg_match('/{"translatedText":"(.*?)"}/', $in, $out);
//$ttext = conv(api_strip($out[1]));
$ttext = str_replace ('\u0026', '&' , api_strip($out[1]));
//$ttext = api_strip($out[1]);
//$ttext = unicode_encode(api_strip($out[1]), 'utf-8');

/* Save to cache */
if ($enablecache && (strlen($ttext)>0)) {
  $length = strlen($text);

  if (!mysql_ping()) {
    mysql_close();
    establishConnection();
  }
 
  if ($length<=50) {
    mysql_query("INSERT IGNORE INTO wt_cache_short SET tl='".addslashes($tl)."', originaltext='".addslashes($text)."', translated='".addslashes(trim($ttext))."'") or die('Insert to short cache failed: ' . mysql_error());
  } else if ($length > 255) {
    mysql_query("INSERT INTO wt_cache SET tl='".addslashes($tl)."', originaltext='".addslashes($text)."', translated='".addslashes(trim($ttext))."'") or die('Insert to normal cache failed: ' . mysql_error());
  } else {
    mysql_query("INSERT IGNORE INTO wt_cache_medium SET tl='".addslashes($tl)."', originaltext='".addslashes($text)."', translated='".addslashes(trim($ttext))."'") or die('Insert to medium cache failed: ' . mysql_error());
  }
}
/* -- */

return $lsto.$ttext.$rsto;
}


function callback($buffer){
global $fl;
$modifyhref = false;
//-------------------------------------------------------------------------------
global $enablesession;

// Get language setting from queries:
$lang = stripslashes(@$_GET['hl']);

if ($enablesession) {
        // Save setting to server session [1]
        // If language setting not found in queries, check session data: [2]
        if (checklang($lang)) $_SESSION['lang'] = $lang; else $lang = @$_SESSION['lang'];
}

if (!checklang($lang) || $lang == $fl) { // If invalid language setting or language = original language, skip translation.

$tp = $buffer;
$tp = preg_replace("/<disp_lang>/is", checklang($fl), $tp);
return remove_tags($tp);

} else {
    // Extract BUFFER
$tp = preg_replace("/(^|>\/?)([^><]*)($|\/?<)/e",
            "emodfix('\\1').translate(emodfix('\\2'),'$fl','$lang').emodfix('\\3')",
            $buffer);

if ($modifyhref) {
$tp = preg_replace('/(<a [^><]*href\=")([^"]*)("[^><]*>)/e',
            "emodfix('\\1').langconv('$lang',emodfix('\\2')).emodfix('\\3')",
            $tp);

$tp = preg_replace('/(<form [^><]*action\=")([^"]*)("[^><]*>)/e',
            "emodfix('\\1').langconv('$lang',emodfix('\\2')).emodfix('\\3'))",
            $tp);
}

$tp = preg_replace("/<disp_lang>/is", checklang($lang), $tp);
    $tp = remove_tags($tp);
return $tp;

}
//---end function
}

function langconv($hl, $href){
if ($href && substr($href, 0, 7) != 'http://' && substr($href, 0, 11) != 'javascript:' && strpos($href, "#") === false) {
        if(strpos($href, "?") === false) return $href.'?hl='.urlencode($hl); else return $href.'&hl='.urlencode($hl);
} else { return $href; }
}

function checklang($hl){
$langvar = array ("sq"=>"Albanian","ar"=>"Arabic","bg"=>"Bulgarian","ca"=>"Catalan","zh-CN"=>"Chinese","hr"=>"Croatian","cs"=>"Czech","da"=>"Danish","nl"=>"Dutch","en"=>"English","et"=>"Estonian","tl"=>"Filipino","fi"=>"Finnish","fr"=>"French","gl"=>"Galician","de"=>"German","el"=>"Greek","iw"=>"Hebrew","hi"=>"Hindi","hu"=>"Hungarian","id"=>"Indonesian","it"=>"Italian","ja"=>"Japanese","ko"=>"Korean","lv"=>"Latvian","lt"=>"Lithuanian","mt"=>"Maltese","no"=>"Norwegian","pl"=>"Polish","pt"=>"Portuguese","ro"=>"Romanian","ru"=>"Russian","sr"=>"Serbian","sk"=>"Slovak","sl"=>"Slovenian","es"=>"Spanish","sv"=>"Swedish","zh-TW"=>"Taiwanese","th"=>"Thai","tr"=>"Turkish","uk"=>"Ukrainian","vi"=>"Vietnamese");
foreach ($langvar as $i => $val){ if ($i == $hl) return $val; }
return false;
}

function clearlangsetting(){
global $enablesession;
if ($enablesession) $_SESSION['lang'] = null; /* -Clear lang session data on server- */
}

?>

Hope Dave will include it in next release.

Now - for already installed products
Here we have 2 ways. Easy one, and good one.

In easy one - just drop all tables from DB, set it from new script and change translate.php like described.

In good one - you want to keep already cached data, and this will need some changes.
1. change translate.php like described
2. dissable cache - set $enablecache=false; in translate.php
3. change collate by executing:
Code:

Alter table wt_cache_short collate utf8_bin;
ALTER TABLE wt_cache_short CHANGE tl tl VARCHAR( 10 ) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL;
ALTER TABLE wt_cache_short CHANGE originaltext originaltext VARCHAR( 50 ) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL;
ALTER TABLE wt_cache_short CHANGE translated translated VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL;

Alter table wt_cache_medium collate utf8_bin;
ALTER TABLE wt_cache_medium CHANGE tl tl VARCHAR( 10 ) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL;
ALTER TABLE wt_cache_medium CHANGE originaltext originaltext VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL;
ALTER TABLE wt_cache_medium CHANGE translated translated VARCHAR( 1000 ) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL;

Alter table wt_cache collate utf8_bin;
ALTER TABLE wt_cache CHANGE tl tl VARCHAR( 10 ) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL;
ALTER TABLE wt_cache CHANGE translated translated TEXT CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL;
ALTER TABLE wt_cache CHANGE translated translated VARCHAR( 65000 ) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL;

4. Delete data duplication like described here (note this is very important - otherwise unique indexes will not be set): https://vborg.vbsupport.ru/showpost....&postcount=282

Note that this step if time consuming and it is a chance that you will need to connect to DB with other client that WWW (just check it first). Remember - always you can use the easy way ;)

5. Optimize tables:
Code:

OPTIMIZE TABLE wt_cache, wt_cache_medium, wt_cache_short;
6. Reindex to unique:
Code:

alter table wt_cache_short drop index originaltext;
create UNIQUE INDEX originaltext on wt_cache_short (originaltext, tl);

alter table wt_cache_medium drop index originaltext;
create UNIQUE INDEX originaltext on wt_cache_medium (originaltext, tl);

7. enable cache - set $enablecache=true; in translate.php


And that is. As I wrote data duplication will disappear for ever from wt_cache_short and wt_cache_medium. Also it will be save in case of hazard described in my 2 previous posts. Also according to my automatic tests - page generation works faster.

So - enjoy :D

CThiessen 07-05-2009 04:17 AM

Quote:

Originally Posted by Dave Hybrid (Post 1842836)
Is it me or is that software really slow, It take ages to crawl normal pages too.

Hello,
Yes it is slow. But store all results in a local Database. So you are able to stop and continue the test at any time. I used Xenu to check Links but that one considers the translated pages an even some Links to social networks as broken because they do not answered in time.
This one I set up on my Computer at work and leave it running over the weekend. I do set it up to waiting time 120 (90 should be enough) an 30 workers. To stop a test and run a report even takes some time. But it?s OK for me as I don?t need to start from the beginning, I going to continue the test every COB until the next morning.

Christian

masterweb 07-05-2009 06:56 AM

Great hack!, i downloaded it 2 days ago due i prefer test a mod before replying with my feedbacks and what i saw is:

After installing it on my Demo board and following the instructions carefully (at first instructions seems complicated but even if is a long procedure if you follow each steep as mentioned it works without problems), i uploaded the flag's folder on root and made the necessary changes to the style...at the end it works without problems and it translated some pages on a decent timeframe.

Then i installed it on my real board and as mentioned above following each steep present on the instructions it works fine, congratulations dude and thanks for this release, now i have just a question:

The main language of my board is the English (i deleted the EN line on the translate.php) but there are sections on Spanish and Italian too so, must i delete also these lines on the translate.php?. Thanks once again.-

Dave Hybrid 07-05-2009 09:34 AM

Quote:

Originally Posted by Sweeks (Post 1842968)
It seems to have ceased working for me, I may try a reinstall, what is best Dave? Thanks :up:

What is the problem, looks ok to me...

Dave Hybrid 07-05-2009 09:58 AM

Quote:

Originally Posted by NLP-er (Post 1842972)
Hello. Just worked out for you another data base update which will made it without data duplication and also faster :)

So really on one table still you can have duplicated data, because of mysql unique limitations I didn't set it in wt_cache, but this table has less data than other updated tables.

Also collate was changed - believe it works faster when makes collation by binary values, that by some additional rules like in previous DB.

To have faster DB without data duplication You have to.

For new installations
Here is new DB:
Code:

CREATE TABLE wt_cache (
id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
tl VARCHAR(10),
originaltext VARCHAR(65000),
translated TEXT,
INDEX(originaltext(50), tl)
) ENGINE = MYISAM, CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE wt_cache_medium (
id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
tl VARCHAR(10),
originaltext VARCHAR(255),
translated VARCHAR(1000),
UNIQUE (originaltext, tl)
) ENGINE = MYISAM, CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE wt_cache_short (
id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
tl VARCHAR(10),
originaltext VARCHAR(50),
translated VARCHAR(255),
UNIQUE (originaltext, tl)
) ENGINE = MYISAM, CHARACTER SET utf8 COLLATE utf8_bin;

Also change code in translate.php
this one:
Code:

/* Check cache for translation */
if ($enablecache) {
  $sql=null;
  $length = strlen($text);
  if ($length<=50) {
    $sql = mysql_query("SELECT translated FROM wt_cache_short WHERE originaltext='".addslashes($text)."' AND tl='".addslashes($tl)."' LIMIT 1"); 
  } else if ($length > 255) {
    $sql = mysql_query("SELECT translated FROM wt_cache WHERE originaltext='".addslashes($text)."' AND tl='".addslashes($tl)."' LIMIT 1");
  } else {
    $sql = mysql_query("SELECT translated FROM wt_cache_medium WHERE originaltext='".addslashes($text)."' AND tl='".addslashes($tl)."' LIMIT 1");
  }
 
        while($t = mysql_fetch_array($sql)) {
                return $lsto.$t['translated'].$rsto;
        }
}
/* -- if not found, proceed with Google Translate */

To this one:
Code:

/* Check cache for translation */
if ($enablecache) {
  $sql=null;
  $length = strlen($text);

  if ($length<=50) {
    $sql = mysql_query("SELECT translated FROM wt_cache_short WHERE originaltext='".addslashes($text)."' AND tl='".addslashes($tl)."'") or die('Query to short cache failed: ' . mysql_error());
  } else if ($length > 255) {
    $sql = mysql_query("SELECT translated FROM wt_cache WHERE originaltext='".addslashes($text)."' AND tl='".addslashes($tl)."' LIMIT 1") or die('Query to normal cache failed: ' . mysql_error());
  } else {
    $sql = mysql_query("SELECT translated FROM wt_cache_medium WHERE originaltext='".addslashes($text)."' AND tl='".addslashes($tl)."'") or die('Query to medium cache failed: ' . mysql_error());
  }
 
        while($t = mysql_fetch_array($sql)) {
                return $lsto.$t['translated'].$rsto;
        }
}
/* -- if not found, proceed with Google Translate */

And change this one:
Code:

////////////////////////////////////////////////////
if ($enablecache) {
mysql_connect ($mysqlserver, $dbusername, $dbpassword);
mysql_select_db ($dbname);
mysql_set_charset('utf8');
}
////////////////////////////////////////////////////

To this one (less white screns):
Code:

////////////////////////////////////////////////////
if ($enablecache) {
  establishConnection();
}


function establishConnection() {
  global $dbusername, $dbpassword, $mysqlserver, $dbname;
  mysql_connect ($mysqlserver, $dbusername, $dbpassword) or die('Could not connect: ' . mysql_error());
  mysql_select_db ($dbname) or die('Could not select database');
  mysql_set_charset('utf8');
}
////////////////////////////////////////////////////

And last change. This one:
Code:

/* Save to cache */
if ($enablecache && (strlen($ttext)>0)) {
  $length = strlen($text);
  if ($length<=50) {
    mysql_query("INSERT INTO wt_cache_short SET tl='".addslashes($tl)."', originaltext='".addslashes($text)."', translated='".addslashes(trim($ttext))."'");
  } else if ($length > 255) {
    mysql_query("INSERT INTO wt_cache SET tl='".addslashes($tl)."', originaltext='".addslashes($text)."', translated='".addslashes(trim($ttext))."'");
  } else {
    mysql_query("INSERT INTO wt_cache_medium SET tl='".addslashes($tl)."', originaltext='".addslashes($text)."', translated='".addslashes(trim($ttext))."'");
  }
}
/* -- */

To this one:
Code:

/* Save to cache */
if ($enablecache && (strlen($ttext)>0)) {
  $length = strlen($text);

  if (!mysql_ping()) {
    mysql_close();
    establishConnection();
  }
 
  if ($length<=50) {
    mysql_query("INSERT IGNORE INTO wt_cache_short SET tl='".addslashes($tl)."', originaltext='".addslashes($text)."', translated='".addslashes(trim($ttext))."'") or die('Insert to short cache failed: ' . mysql_error());
  } else if ($length > 255) {
    mysql_query("INSERT INTO wt_cache SET tl='".addslashes($tl)."', originaltext='".addslashes($text)."', translated='".addslashes(trim($ttext))."'") or die('Insert to normal cache failed: ' . mysql_error());
  } else {
    mysql_query("INSERT IGNORE INTO wt_cache_medium SET tl='".addslashes($tl)."', originaltext='".addslashes($text)."', translated='".addslashes(trim($ttext))."'") or die('Insert to medium cache failed: ' . mysql_error());
  }
}
/* -- */

So whole new translate.php is:
Code:

<?php
////////////////////////////////////////////////////
// Global Translator API
////////////////////////////////////////////////////

global $enablesession, $enablecache, $originalEncoding, $fl;
global $dbusername, $dbpassword, $mysqlserver, $dbname;

////////////////////////////////////////////////////
//        SETTINGS
////////////////////////////////////////////////////
$enablesession = false; //ignore
$enablecache = true; //true - enable cache setting, false - disable cache setting
$originalEncoding = 'iso-8859-1'; //refer to your forum source code for your base encoding
$fl = 'en'; //current language (original) - refer table for language variables

$dbusername = "SET_IT";
$dbpassword = "SET_IT";
$mysqlserver = "localhost";
$dbname = "SET_IT";

////////////////////////////////////////////////////

if ($enablesession) {
        @session_name("iPWTLang");
        @session_start();
}


set_time_limit(0);


////////////////////////////////////////////////////
if ($enablecache) {
  establishConnection();
}


function establishConnection() {
  global $dbusername, $dbpassword, $mysqlserver, $dbname;
  mysql_connect ($mysqlserver, $dbusername, $dbpassword) or die('Could not connect: ' . mysql_error());
  mysql_select_db ($dbname) or die('Could not select database');
  mysql_set_charset('utf8');
}
////////////////////////////////////////////////////

function api_strip ($dt) { $dt = str_replace("\\\\", '\\', $dt); return ($dt); }

function emodfix ($dt) { $dt = str_replace('\"', '"', $dt); return ($dt); }

function remove_tags ($html) {
/* Remove reserved triple tags in html */
return preg_replace ("|<<<([^><]*)>>>|e", "emodfix('\\1')", $html);
}

function add_tags ($buffer) {
/* Inject triple tags to html to preserve html content from translation using ob_start */
return preg_replace("/(^|>\/?)([^><]*)($|\/?<)/e",
            "emodfix('\\1').'<<<'.emodfix('\\2').'>>>'.emodfix('\\3')",
            $buffer);
}

function getServerLoad($windows=false)
{
//MY CODE TO DISABLE SERVER LOAD CHEcKING
  return 1;
//END

    $os = strtolower(PHP_OS);
    if (strpos($os, "win") === false) {
        if (file_exists("/proc/loadavg")) {
            $data = file_get_contents("/proc/loadavg");
            $load = explode(' ', $data);
            return $load[0];

        } elseif (function_exists("shell_exec")) {

            $load = explode(' ', `uptime`);
            return $load[count($load)-1];

        } else {

            return false;
        }

    } elseif($windows) {

        if(class_exists("COM")) {
            $wmi = new COM("WinMgmts:\\\\.");
            $cpus = $wmi->InstancesOf("Win32_Processor");

            $cpuload = 0;
            $i = 0;

            if(version_compare('4.50.0', PHP_VERSION) == 1) {
                // PHP 4
                while ($cpu = $cpus->Next()) {
                    $cpuload += $cpu->LoadPercentage;
                    $i++;
                }

            } else {

                // PHP 5
                foreach ( $cpus as $cpu ) {
                    $cpuload += $cpu->LoadPercentage;
                    $i++;
                }
            }

            $cpuload = round($cpuload / $i, 2);
            return "$cpuload%";

        } else {

            return false;
        }
    }
}

function translate($text, $fl, $tl){
if (trim($text) == null) return $text; //skip translation if string empty

/* Retain left and right spaces after translation */
$lsto = substr($text, 0, strlen($text) - strlen(ltrim($text)));
$rsto = substr($text, strlen(rtrim($text)), strlen($text) - strlen(rtrim($text)));
/* -- */

/* Declare global */
global $enablecache,$overloadval,$disinterval;
if(floatval(getServerLoad()) >= 1.5)    // Numeral = server load on which to crash
{

    // Write current time to file.
    $fp = fopen("overloadcache.txt","w");
    fwrite($fp, time() . "");
    fclose($fp);


  if($nfh= @fopen("overloadcache.txt","r"))
  {
      $overloadtime = fgets($nfh);
      if($overloadtime > time()-30)  // Numeral = # seconds after overload not to cache!
      {
          $enablecache = false;
      }
      fclose($nfh);
  }
}

/* Check for server overloads  (modification by DeViAnThans3)*/
global $originalEncoding;
if ($originalEncoding != 'utf-8') {
  $text = iconv($originalEncoding, 'utf-8', trim($text));
} else {
  $text = trim($text);
}

/* Check cache for translation */
if ($enablecache) {
  $sql=null;
  $length = strlen($text);
/*
  if (!mysql_ping()) {
    mysql_close();
    establishConnection();
  }
*/ 
  if ($length<=50) {
    $sql = mysql_query("SELECT translated FROM wt_cache_short WHERE originaltext='".addslashes($text)."' AND tl='".addslashes($tl)."'") or die('Query to short cache failed: ' . mysql_error());
  } else if ($length > 255) {
    $sql = mysql_query("SELECT translated FROM wt_cache WHERE originaltext='".addslashes($text)."' AND tl='".addslashes($tl)."' LIMIT 1") or die('Query to normal cache failed: ' . mysql_error());
  } else {
    $sql = mysql_query("SELECT translated FROM wt_cache_medium WHERE originaltext='".addslashes($text)."' AND tl='".addslashes($tl)."'") or die('Query to medium cache failed: ' . mysql_error());
  }
 
        while($t = mysql_fetch_array($sql)) {
                return $lsto.$t['translated'].$rsto;
        }
}
/* -- if not found, proceed with Google Translate */

/* -Establish cURL connection to Google Translate API server- */
$ch = @curl_init();
//@curl_setopt($ch, CURLOPT_URL, "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&langpair=".urlencode($fl.'|'.$tl)."&q=".urlencode($text));

@curl_setopt($ch, CURLOPT_URL, "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&langpair=".urlencode($fl.'|'.$tl)."&q=".urlencode($text));

//$postParams = "v=1.0&langpair=".$fl.'|'.$tl."&q=".iconv('iso-8859-2', 'utf-8', $text);
//@curl_setopt($ch, CURLOPT_URL, "http://ajax.googleapis.com/ajax/services/language/translate");
//@curl_setopt ($Curl_Session, CURLOPT_POST, 1);
//@curl_setopt ($Curl_Session, CURLOPT_POSTFIELDS, $postParams);

@curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)");
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$in = @curl_exec ($ch);
/* -End connection- */

preg_match('/{"translatedText":"(.*?)"}/', $in, $out);
//$ttext = conv(api_strip($out[1]));
$ttext = str_replace ('\u0026', '&' , api_strip($out[1]));
//$ttext = api_strip($out[1]);
//$ttext = unicode_encode(api_strip($out[1]), 'utf-8');

/* Save to cache */
if ($enablecache && (strlen($ttext)>0)) {
  $length = strlen($text);

  if (!mysql_ping()) {
    mysql_close();
    establishConnection();
  }
 
  if ($length<=50) {
    mysql_query("INSERT IGNORE INTO wt_cache_short SET tl='".addslashes($tl)."', originaltext='".addslashes($text)."', translated='".addslashes(trim($ttext))."'") or die('Insert to short cache failed: ' . mysql_error());
  } else if ($length > 255) {
    mysql_query("INSERT INTO wt_cache SET tl='".addslashes($tl)."', originaltext='".addslashes($text)."', translated='".addslashes(trim($ttext))."'") or die('Insert to normal cache failed: ' . mysql_error());
  } else {
    mysql_query("INSERT IGNORE INTO wt_cache_medium SET tl='".addslashes($tl)."', originaltext='".addslashes($text)."', translated='".addslashes(trim($ttext))."'") or die('Insert to medium cache failed: ' . mysql_error());
  }
}
/* -- */

return $lsto.$ttext.$rsto;
}


function callback($buffer){
global $fl;
$modifyhref = false;
//-------------------------------------------------------------------------------
global $enablesession;

// Get language setting from queries:
$lang = stripslashes(@$_GET['hl']);

if ($enablesession) {
        // Save setting to server session [1]
        // If language setting not found in queries, check session data: [2]
        if (checklang($lang)) $_SESSION['lang'] = $lang; else $lang = @$_SESSION['lang'];
}

if (!checklang($lang) || $lang == $fl) { // If invalid language setting or language = original language, skip translation.

$tp = $buffer;
$tp = preg_replace("/<disp_lang>/is", checklang($fl), $tp);
return remove_tags($tp);

} else {
    // Extract BUFFER
$tp = preg_replace("/(^|>\/?)([^><]*)($|\/?<)/e",
            "emodfix('\\1').translate(emodfix('\\2'),'$fl','$lang').emodfix('\\3')",
            $buffer);

if ($modifyhref) {
$tp = preg_replace('/(<a [^><]*href\=")([^"]*)("[^><]*>)/e',
            "emodfix('\\1').langconv('$lang',emodfix('\\2')).emodfix('\\3')",
            $tp);

$tp = preg_replace('/(<form [^><]*action\=")([^"]*)("[^><]*>)/e',
            "emodfix('\\1').langconv('$lang',emodfix('\\2')).emodfix('\\3'))",
            $tp);
}

$tp = preg_replace("/<disp_lang>/is", checklang($lang), $tp);
    $tp = remove_tags($tp);
return $tp;

}
//---end function
}

function langconv($hl, $href){
if ($href && substr($href, 0, 7) != 'http://' && substr($href, 0, 11) != 'javascript:' && strpos($href, "#") === false) {
        if(strpos($href, "?") === false) return $href.'?hl='.urlencode($hl); else return $href.'&hl='.urlencode($hl);
} else { return $href; }
}

function checklang($hl){
$langvar = array ("sq"=>"Albanian","ar"=>"Arabic","bg"=>"Bulgarian","ca"=>"Catalan","zh-CN"=>"Chinese","hr"=>"Croatian","cs"=>"Czech","da"=>"Danish","nl"=>"Dutch","en"=>"English","et"=>"Estonian","tl"=>"Filipino","fi"=>"Finnish","fr"=>"French","gl"=>"Galician","de"=>"German","el"=>"Greek","iw"=>"Hebrew","hi"=>"Hindi","hu"=>"Hungarian","id"=>"Indonesian","it"=>"Italian","ja"=>"Japanese","ko"=>"Korean","lv"=>"Latvian","lt"=>"Lithuanian","mt"=>"Maltese","no"=>"Norwegian","pl"=>"Polish","pt"=>"Portuguese","ro"=>"Romanian","ru"=>"Russian","sr"=>"Serbian","sk"=>"Slovak","sl"=>"Slovenian","es"=>"Spanish","sv"=>"Swedish","zh-TW"=>"Taiwanese","th"=>"Thai","tr"=>"Turkish","uk"=>"Ukrainian","vi"=>"Vietnamese");
foreach ($langvar as $i => $val){ if ($i == $hl) return $val; }
return false;
}

function clearlangsetting(){
global $enablesession;
if ($enablesession) $_SESSION['lang'] = null; /* -Clear lang session data on server- */
}

?>

Hope Dave will include it in next release.

Now - for already installed products
Here we have 2 ways. Easy one, and good one.

In easy one - just drop all tables from DB, set it from new script and change translate.php like described.

In good one - you want to keep already cached data, and this will need some changes.
1. change translate.php like described
2. change collate by executing:
Code:

Alter table wt_cache_short collate utf8_bin;
ALTER TABLE wt_cache_short CHANGE tl tl VARCHAR( 10 ) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL;
ALTER TABLE wt_cache_short CHANGE originaltext originaltext VARCHAR( 50 ) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL;
ALTER TABLE wt_cache_short CHANGE translated translated VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL;

Alter table wt_cache_medium collate utf8_bin;
ALTER TABLE wt_cache_medium CHANGE tl tl VARCHAR( 10 ) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL;
ALTER TABLE wt_cache_medium CHANGE originaltext originaltext VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL;
ALTER TABLE wt_cache_medium CHANGE translated translated VARCHAR( 1000 ) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL;

Alter table wt_cache collate utf8_bin;
ALTER TABLE wt_cache CHANGE tl tl VARCHAR( 10 ) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL;
ALTER TABLE wt_cache CHANGE translated translated TEXT CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL;
ALTER TABLE wt_cache CHANGE translated translated VARCHAR( 65000 ) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL;

3. Delete data duplication like described here (note this is very important - otherwise unique indexes will not be set): https://vborg.vbsupport.ru/showpost....&postcount=214

Note that this step if very time consuming and probably you will need to connect to DB with other client that WWW. Remember - always you can use the easy way ;)

4. Optimize tables:
Code:

OPTIMIZE TABLE wt_cache, wt_cache_medium, wt_cache_short;
5. Reindex to unique:
Code:

alter table wt_cache_short drop index originaltext;
create UNIQUE INDEX originaltext on wt_cache_short (originaltext, tl);

alter table wt_cache_medium drop index originaltext;
create UNIQUE INDEX originaltext on wt_cache_medium (originaltext, tl);

And that is. As I wrote data duplication will disappear for ever from wt_cache_short and wt_cache_medium. Also it will be save in case of hazard described in my 2 previous posts. Also according to my automatic tests - page generation works faster.

So - enjoy :D

Error

SQL query:

CREATE UNIQUE INDEX originaltext ON wt_cache_medium(
originaltext,
tl
);

MySQL said: Documentation
#1062 - Duplicate entry 'I even learned a few bits, the number range in particular will c' for key 2

***********

Edit

Seems ok now, just run the query again. Would still appreciate an explanation of the error, thanks mate.

Dave Hybrid 07-05-2009 10:09 AM

I don't know what you did but it's slow, really slow, unbearable. Something isnt right with your changes.

Dave Hybrid 07-05-2009 10:55 AM

In your version is causes crazy high server load, and cache false doesnt seem to work anymore.

NLP-er 07-05-2009 11:05 AM

Quote:

Originally Posted by Dave Hybrid (Post 1843115)
I don't know what you did but it's slow, really slow, unbearable. Something isnt right with your changes.

Of course - you just wrote that you didn't made UNIQUE INDEX - so you just came back to time which you had in your very first release.

Once again:
Delete data duplication like described here (note this is very important - otherwise unique indexes will not be set)

And you had data duplication:
#1062 - Duplicate entry

So you don't have index now - it have to be slow :p

My changes are ok and make it works faster - just have to make all steps.

If you had error with data duplication - drop duplicated data. If you did it and have same problem - drop data duplication again - it just means that in the meantime between dropping data duplication and trying to create UNIQUE INDEX, some new data came with duplications (google doesn't sleep).

Before you will drop duplicated data again it is wise to set normal index again:
Code:

create INDEX originaltext on wt_cache_short (originaltext, tl);
then drop data duplication and reindex to unique as described in previous post :)

As I wrote - you always have the easy way. You want keep your cache - made everything as described and don't complain that with my update is something wrong if you didn't make it.

NLP-er 07-05-2009 11:13 AM

Quote:

Originally Posted by Dave Hybrid (Post 1843132)
In your version is causes crazy high server load, and cache false doesnt seem to work anymore.

Time consuming is deletion of data duplication and also reindexing. It was mentioned in description - mysql have some work and it is only during the changes - script is working faster. Also always have the easy way :p

$enablecache works fine - possible that mysql still works on some of your queries from deleting data duplication and slows down the system.

But it is good idea - disable cache before deleting data duplication and enable it again after all changes :) You will not have problems with data duplication in the meantime. I will add those 2 points to update description

Dave Hybrid 07-05-2009 11:15 AM

Ok, but i ran your duplication update a few days ago, i have to run it again for this update too?

NLP-er 07-05-2009 11:50 AM

Quote:

Originally Posted by Dave Hybrid (Post 1843145)
Ok, but i ran your duplication update a few days ago, i have to run it again for this update too?

YES! As I wrote - before my update it is possible that data are duplicated, when some pages are translated in same time. spiders usually works with friends ;) So since your last removal you have again duplication. It will not happen again after this update (ok it will but only for table wt_cache - it's mysql limitation, but tables with biggest amount of data will not have duplicated data again).

Dave Hybrid 07-05-2009 12:59 PM

Understood, i'll try again in a bit and then update the main install. Thanks.

jaryx 07-05-2009 04:36 PM

Does anyone use vBseo Relevant Replacement?

RR also be translated? Unfortunately, not on my forum :/

mike2902 07-05-2009 07:40 PM

Can someone help me understand this. The goal of this MOD is to get a flood of international traffic. This traffic is unlikely to stick around because of the language issue so whats the point of wanting all this traffic.

Dave Hybrid 07-05-2009 08:30 PM

Quote:

Originally Posted by mike2902 (Post 1843363)
Can someone help me understand this. The goal of this MOD is to get a flood of international traffic. This traffic is unlikely to stick around because of the language issue so whats the point of wanting all this traffic.

Same reason you want normal traffic, not everyone wants to stay and chat with them either.

For me I use it for ad revenue, branding, future referrals from word of mouth to UK traffic, it's free exposure.

Your mileage may vary.

Dave Hybrid 07-05-2009 08:50 PM

Quote:

Originally Posted by NLP-er (Post 1842972)
Hello. Just worked out for you another data base update which will made it without data duplication and also faster :)

So really on one table still you can have duplicated data, because of mysql unique limitations I didn't set it in wt_cache, but this table has less data than other updated tables.

Also collate was changed - believe it works faster when makes collation by binary values, that by some additional rules like in previous DB.

To have faster DB without data duplication You have to.

For new installations
Here is new DB:
Code:

CREATE TABLE wt_cache (
id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
tl VARCHAR(10),
originaltext VARCHAR(65000),
translated TEXT,
INDEX(originaltext(50), tl)
) ENGINE = MYISAM, CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE wt_cache_medium (
id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
tl VARCHAR(10),
originaltext VARCHAR(255),
translated VARCHAR(1000),
UNIQUE (originaltext, tl)
) ENGINE = MYISAM, CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE wt_cache_short (
id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
tl VARCHAR(10),
originaltext VARCHAR(50),
translated VARCHAR(255),
UNIQUE (originaltext, tl)
) ENGINE = MYISAM, CHARACTER SET utf8 COLLATE utf8_bin;

Also change code in translate.php
this one:
Code:

/* Check cache for translation */
if ($enablecache) {
  $sql=null;
  $length = strlen($text);
  if ($length<=50) {
    $sql = mysql_query("SELECT translated FROM wt_cache_short WHERE originaltext='".addslashes($text)."' AND tl='".addslashes($tl)."' LIMIT 1"); 
  } else if ($length > 255) {
    $sql = mysql_query("SELECT translated FROM wt_cache WHERE originaltext='".addslashes($text)."' AND tl='".addslashes($tl)."' LIMIT 1");
  } else {
    $sql = mysql_query("SELECT translated FROM wt_cache_medium WHERE originaltext='".addslashes($text)."' AND tl='".addslashes($tl)."' LIMIT 1");
  }
 
        while($t = mysql_fetch_array($sql)) {
                return $lsto.$t['translated'].$rsto;
        }
}
/* -- if not found, proceed with Google Translate */

To this one:
Code:

/* Check cache for translation */
if ($enablecache) {
  $sql=null;
  $length = strlen($text);

  if ($length<=50) {
    $sql = mysql_query("SELECT translated FROM wt_cache_short WHERE originaltext='".addslashes($text)."' AND tl='".addslashes($tl)."'") or die('Query to short cache failed: ' . mysql_error());
  } else if ($length > 255) {
    $sql = mysql_query("SELECT translated FROM wt_cache WHERE originaltext='".addslashes($text)."' AND tl='".addslashes($tl)."' LIMIT 1") or die('Query to normal cache failed: ' . mysql_error());
  } else {
    $sql = mysql_query("SELECT translated FROM wt_cache_medium WHERE originaltext='".addslashes($text)."' AND tl='".addslashes($tl)."'") or die('Query to medium cache failed: ' . mysql_error());
  }
 
        while($t = mysql_fetch_array($sql)) {
                return $lsto.$t['translated'].$rsto;
        }
}
/* -- if not found, proceed with Google Translate */

And change this one:
Code:

////////////////////////////////////////////////////
if ($enablecache) {
mysql_connect ($mysqlserver, $dbusername, $dbpassword);
mysql_select_db ($dbname);
mysql_set_charset('utf8');
}
////////////////////////////////////////////////////

To this one (less white screns):
Code:

////////////////////////////////////////////////////
if ($enablecache) {
  establishConnection();
}


function establishConnection() {
  global $dbusername, $dbpassword, $mysqlserver, $dbname;
  mysql_connect ($mysqlserver, $dbusername, $dbpassword) or die('Could not connect: ' . mysql_error());
  mysql_select_db ($dbname) or die('Could not select database');
  mysql_set_charset('utf8');
}
////////////////////////////////////////////////////

And last change. This one:
Code:

/* Save to cache */
if ($enablecache && (strlen($ttext)>0)) {
  $length = strlen($text);
  if ($length<=50) {
    mysql_query("INSERT INTO wt_cache_short SET tl='".addslashes($tl)."', originaltext='".addslashes($text)."', translated='".addslashes(trim($ttext))."'");
  } else if ($length > 255) {
    mysql_query("INSERT INTO wt_cache SET tl='".addslashes($tl)."', originaltext='".addslashes($text)."', translated='".addslashes(trim($ttext))."'");
  } else {
    mysql_query("INSERT INTO wt_cache_medium SET tl='".addslashes($tl)."', originaltext='".addslashes($text)."', translated='".addslashes(trim($ttext))."'");
  }
}
/* -- */

To this one:
Code:

/* Save to cache */
if ($enablecache && (strlen($ttext)>0)) {
  $length = strlen($text);

  if (!mysql_ping()) {
    mysql_close();
    establishConnection();
  }
 
  if ($length<=50) {
    mysql_query("INSERT IGNORE INTO wt_cache_short SET tl='".addslashes($tl)."', originaltext='".addslashes($text)."', translated='".addslashes(trim($ttext))."'") or die('Insert to short cache failed: ' . mysql_error());
  } else if ($length > 255) {
    mysql_query("INSERT INTO wt_cache SET tl='".addslashes($tl)."', originaltext='".addslashes($text)."', translated='".addslashes(trim($ttext))."'") or die('Insert to normal cache failed: ' . mysql_error());
  } else {
    mysql_query("INSERT IGNORE INTO wt_cache_medium SET tl='".addslashes($tl)."', originaltext='".addslashes($text)."', translated='".addslashes(trim($ttext))."'") or die('Insert to medium cache failed: ' . mysql_error());
  }
}
/* -- */

So whole new translate.php is:
Code:

<?php
////////////////////////////////////////////////////
// Global Translator API
////////////////////////////////////////////////////

global $enablesession, $enablecache, $originalEncoding, $fl;
global $dbusername, $dbpassword, $mysqlserver, $dbname;

////////////////////////////////////////////////////
//        SETTINGS
////////////////////////////////////////////////////
$enablesession = false; //ignore
$enablecache = true; //true - enable cache setting, false - disable cache setting
$originalEncoding = 'iso-8859-1'; //refer to your forum source code for your base encoding
$fl = 'en'; //current language (original) - refer table for language variables

$dbusername = "SET_IT";
$dbpassword = "SET_IT";
$mysqlserver = "localhost";
$dbname = "SET_IT";

////////////////////////////////////////////////////

if ($enablesession) {
        @session_name("iPWTLang");
        @session_start();
}


set_time_limit(0);


////////////////////////////////////////////////////
if ($enablecache) {
  establishConnection();
}


function establishConnection() {
  global $dbusername, $dbpassword, $mysqlserver, $dbname;
  mysql_connect ($mysqlserver, $dbusername, $dbpassword) or die('Could not connect: ' . mysql_error());
  mysql_select_db ($dbname) or die('Could not select database');
  mysql_set_charset('utf8');
}
////////////////////////////////////////////////////

function api_strip ($dt) { $dt = str_replace("\\\\", '\\', $dt); return ($dt); }

function emodfix ($dt) { $dt = str_replace('\"', '"', $dt); return ($dt); }

function remove_tags ($html) {
/* Remove reserved triple tags in html */
return preg_replace ("|<<<([^><]*)>>>|e", "emodfix('\\1')", $html);
}

function add_tags ($buffer) {
/* Inject triple tags to html to preserve html content from translation using ob_start */
return preg_replace("/(^|>\/?)([^><]*)($|\/?<)/e",
            "emodfix('\\1').'<<<'.emodfix('\\2').'>>>'.emodfix('\\3')",
            $buffer);
}

function getServerLoad($windows=false)
{
//MY CODE TO DISABLE SERVER LOAD CHEcKING
  return 1;
//END

    $os = strtolower(PHP_OS);
    if (strpos($os, "win") === false) {
        if (file_exists("/proc/loadavg")) {
            $data = file_get_contents("/proc/loadavg");
            $load = explode(' ', $data);
            return $load[0];

        } elseif (function_exists("shell_exec")) {

            $load = explode(' ', `uptime`);
            return $load[count($load)-1];

        } else {

            return false;
        }

    } elseif($windows) {

        if(class_exists("COM")) {
            $wmi = new COM("WinMgmts:\\\\.");
            $cpus = $wmi->InstancesOf("Win32_Processor");

            $cpuload = 0;
            $i = 0;

            if(version_compare('4.50.0', PHP_VERSION) == 1) {
                // PHP 4
                while ($cpu = $cpus->Next()) {
                    $cpuload += $cpu->LoadPercentage;
                    $i++;
                }

            } else {

                // PHP 5
                foreach ( $cpus as $cpu ) {
                    $cpuload += $cpu->LoadPercentage;
                    $i++;
                }
            }

            $cpuload = round($cpuload / $i, 2);
            return "$cpuload%";

        } else {

            return false;
        }
    }
}

function translate($text, $fl, $tl){
if (trim($text) == null) return $text; //skip translation if string empty

/* Retain left and right spaces after translation */
$lsto = substr($text, 0, strlen($text) - strlen(ltrim($text)));
$rsto = substr($text, strlen(rtrim($text)), strlen($text) - strlen(rtrim($text)));
/* -- */

/* Declare global */
global $enablecache,$overloadval,$disinterval;
if(floatval(getServerLoad()) >= 1.5)    // Numeral = server load on which to crash
{

    // Write current time to file.
    $fp = fopen("overloadcache.txt","w");
    fwrite($fp, time() . "");
    fclose($fp);


  if($nfh= @fopen("overloadcache.txt","r"))
  {
      $overloadtime = fgets($nfh);
      if($overloadtime > time()-30)  // Numeral = # seconds after overload not to cache!
      {
          $enablecache = false;
      }
      fclose($nfh);
  }
}

/* Check for server overloads  (modification by DeViAnThans3)*/
global $originalEncoding;
if ($originalEncoding != 'utf-8') {
  $text = iconv($originalEncoding, 'utf-8', trim($text));
} else {
  $text = trim($text);
}

/* Check cache for translation */
if ($enablecache) {
  $sql=null;
  $length = strlen($text);
/*
  if (!mysql_ping()) {
    mysql_close();
    establishConnection();
  }
*/ 
  if ($length<=50) {
    $sql = mysql_query("SELECT translated FROM wt_cache_short WHERE originaltext='".addslashes($text)."' AND tl='".addslashes($tl)."'") or die('Query to short cache failed: ' . mysql_error());
  } else if ($length > 255) {
    $sql = mysql_query("SELECT translated FROM wt_cache WHERE originaltext='".addslashes($text)."' AND tl='".addslashes($tl)."' LIMIT 1") or die('Query to normal cache failed: ' . mysql_error());
  } else {
    $sql = mysql_query("SELECT translated FROM wt_cache_medium WHERE originaltext='".addslashes($text)."' AND tl='".addslashes($tl)."'") or die('Query to medium cache failed: ' . mysql_error());
  }
 
        while($t = mysql_fetch_array($sql)) {
                return $lsto.$t['translated'].$rsto;
        }
}
/* -- if not found, proceed with Google Translate */

/* -Establish cURL connection to Google Translate API server- */
$ch = @curl_init();
//@curl_setopt($ch, CURLOPT_URL, "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&langpair=".urlencode($fl.'|'.$tl)."&q=".urlencode($text));

@curl_setopt($ch, CURLOPT_URL, "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&langpair=".urlencode($fl.'|'.$tl)."&q=".urlencode($text));

//$postParams = "v=1.0&langpair=".$fl.'|'.$tl."&q=".iconv('iso-8859-2', 'utf-8', $text);
//@curl_setopt($ch, CURLOPT_URL, "http://ajax.googleapis.com/ajax/services/language/translate");
//@curl_setopt ($Curl_Session, CURLOPT_POST, 1);
//@curl_setopt ($Curl_Session, CURLOPT_POSTFIELDS, $postParams);

@curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)");
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$in = @curl_exec ($ch);
/* -End connection- */

preg_match('/{"translatedText":"(.*?)"}/', $in, $out);
//$ttext = conv(api_strip($out[1]));
$ttext = str_replace ('\u0026', '&' , api_strip($out[1]));
//$ttext = api_strip($out[1]);
//$ttext = unicode_encode(api_strip($out[1]), 'utf-8');

/* Save to cache */
if ($enablecache && (strlen($ttext)>0)) {
  $length = strlen($text);

  if (!mysql_ping()) {
    mysql_close();
    establishConnection();
  }
 
  if ($length<=50) {
    mysql_query("INSERT IGNORE INTO wt_cache_short SET tl='".addslashes($tl)."', originaltext='".addslashes($text)."', translated='".addslashes(trim($ttext))."'") or die('Insert to short cache failed: ' . mysql_error());
  } else if ($length > 255) {
    mysql_query("INSERT INTO wt_cache SET tl='".addslashes($tl)."', originaltext='".addslashes($text)."', translated='".addslashes(trim($ttext))."'") or die('Insert to normal cache failed: ' . mysql_error());
  } else {
    mysql_query("INSERT IGNORE INTO wt_cache_medium SET tl='".addslashes($tl)."', originaltext='".addslashes($text)."', translated='".addslashes(trim($ttext))."'") or die('Insert to medium cache failed: ' . mysql_error());
  }
}
/* -- */

return $lsto.$ttext.$rsto;
}


function callback($buffer){
global $fl;
$modifyhref = false;
//-------------------------------------------------------------------------------
global $enablesession;

// Get language setting from queries:
$lang = stripslashes(@$_GET['hl']);

if ($enablesession) {
        // Save setting to server session [1]
        // If language setting not found in queries, check session data: [2]
        if (checklang($lang)) $_SESSION['lang'] = $lang; else $lang = @$_SESSION['lang'];
}

if (!checklang($lang) || $lang == $fl) { // If invalid language setting or language = original language, skip translation.

$tp = $buffer;
$tp = preg_replace("/<disp_lang>/is", checklang($fl), $tp);
return remove_tags($tp);

} else {
    // Extract BUFFER
$tp = preg_replace("/(^|>\/?)([^><]*)($|\/?<)/e",
            "emodfix('\\1').translate(emodfix('\\2'),'$fl','$lang').emodfix('\\3')",
            $buffer);

if ($modifyhref) {
$tp = preg_replace('/(<a [^><]*href\=")([^"]*)("[^><]*>)/e',
            "emodfix('\\1').langconv('$lang',emodfix('\\2')).emodfix('\\3')",
            $tp);

$tp = preg_replace('/(<form [^><]*action\=")([^"]*)("[^><]*>)/e',
            "emodfix('\\1').langconv('$lang',emodfix('\\2')).emodfix('\\3'))",
            $tp);
}

$tp = preg_replace("/<disp_lang>/is", checklang($lang), $tp);
    $tp = remove_tags($tp);
return $tp;

}
//---end function
}

function langconv($hl, $href){
if ($href && substr($href, 0, 7) != 'http://' && substr($href, 0, 11) != 'javascript:' && strpos($href, "#") === false) {
        if(strpos($href, "?") === false) return $href.'?hl='.urlencode($hl); else return $href.'&hl='.urlencode($hl);
} else { return $href; }
}

function checklang($hl){
$langvar = array ("sq"=>"Albanian","ar"=>"Arabic","bg"=>"Bulgarian","ca"=>"Catalan","zh-CN"=>"Chinese","hr"=>"Croatian","cs"=>"Czech","da"=>"Danish","nl"=>"Dutch","en"=>"English","et"=>"Estonian","tl"=>"Filipino","fi"=>"Finnish","fr"=>"French","gl"=>"Galician","de"=>"German","el"=>"Greek","iw"=>"Hebrew","hi"=>"Hindi","hu"=>"Hungarian","id"=>"Indonesian","it"=>"Italian","ja"=>"Japanese","ko"=>"Korean","lv"=>"Latvian","lt"=>"Lithuanian","mt"=>"Maltese","no"=>"Norwegian","pl"=>"Polish","pt"=>"Portuguese","ro"=>"Romanian","ru"=>"Russian","sr"=>"Serbian","sk"=>"Slovak","sl"=>"Slovenian","es"=>"Spanish","sv"=>"Swedish","zh-TW"=>"Taiwanese","th"=>"Thai","tr"=>"Turkish","uk"=>"Ukrainian","vi"=>"Vietnamese");
foreach ($langvar as $i => $val){ if ($i == $hl) return $val; }
return false;
}

function clearlangsetting(){
global $enablesession;
if ($enablesession) $_SESSION['lang'] = null; /* -Clear lang session data on server- */
}

?>

Hope Dave will include it in next release.

Now - for already installed products
Here we have 2 ways. Easy one, and good one.

In easy one - just drop all tables from DB, set it from new script and change translate.php like described.

In good one - you want to keep already cached data, and this will need some changes.
1. change translate.php like described
2. dissable cache - set $enablecache=false; in translate.php
3. change collate by executing:
Code:

Alter table wt_cache_short collate utf8_bin;
ALTER TABLE wt_cache_short CHANGE tl tl VARCHAR( 10 ) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL;
ALTER TABLE wt_cache_short CHANGE originaltext originaltext VARCHAR( 50 ) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL;
ALTER TABLE wt_cache_short CHANGE translated translated VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL;

Alter table wt_cache_medium collate utf8_bin;
ALTER TABLE wt_cache_medium CHANGE tl tl VARCHAR( 10 ) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL;
ALTER TABLE wt_cache_medium CHANGE originaltext originaltext VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL;
ALTER TABLE wt_cache_medium CHANGE translated translated VARCHAR( 1000 ) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL;

Alter table wt_cache collate utf8_bin;
ALTER TABLE wt_cache CHANGE tl tl VARCHAR( 10 ) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL;
ALTER TABLE wt_cache CHANGE translated translated TEXT CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL;
ALTER TABLE wt_cache CHANGE translated translated VARCHAR( 65000 ) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL;

4. Delete data duplication like described here (note this is very important - otherwise unique indexes will not be set): https://vborg.vbsupport.ru/showpost....&postcount=214

Note that this step if very time consuming and probably you will need to connect to DB with other client that WWW. Remember - always you can use the easy way ;)

5. Optimize tables:
Code:

OPTIMIZE TABLE wt_cache, wt_cache_medium, wt_cache_short;
6. Reindex to unique:
Code:

alter table wt_cache_short drop index originaltext;
create UNIQUE INDEX originaltext on wt_cache_short (originaltext, tl);

alter table wt_cache_medium drop index originaltext;
create UNIQUE INDEX originaltext on wt_cache_medium (originaltext, tl);

7. enable cache - set $enablecache=true; in translate.php


And that is. As I wrote data duplication will disappear for ever from wt_cache_short and wt_cache_medium. Also it will be save in case of hazard described in my 2 previous posts. Also according to my automatic tests - page generation works faster.

So - enjoy :D

So what happens to saver and cleaner? Do these stay or can i remove them? Thanks.

Dave Hybrid 07-05-2009 10:02 PM

We'll I tried again with your new update.

Had to get my host to run this bit as it times out in the browser.

4. Delete data duplication like described here (note this is very important - otherwise unique indexes will not be set):

They say the query is stuck on delete from cleaner...

So i am going to stick with the current update for now.

NLP-er 07-05-2009 10:05 PM

Quote:

Originally Posted by Dave Hybrid (Post 1843396)
So what happens to saver and cleaner? Do these stay or can i remove them? Thanks.

Those can stay for future wt_cache duplication cleaning - this is only table where duplications still can happen. Fortunately there is less records than in other tables, and it is rare to write there translations (till now in my DB i have 380 000 rows in wt_cache_short; 210 000 in wt_cache_medium; and only 65 000 in wt_cache).

wt_cache cannot have unique index for whole oryginaltext and tl, because oryginaltext is too big for that, and making it's unique only for part of it has some disadvantages. I made tests and mysql allows me to set unique index olny for first 323 letters from oryginaltest and whole tl. So if I do that, then data duplication will be a history in this mod - that's the good part. Worst part is that if we will have 2 different translations with same first 323 letters, then only first one will be cached, and second one will be translated by google every time when page will be generated.

I also realize that it is rare to have 2 different posts which starts from such long same text (323 letters), but it is possible - especially when users like to quote others posts. I've just made a query and I have such cases in my cache. So we can have actual solution which allows data duplication, but we know how to delete duplicated data, and once translated text will never be translated again. Or change it to solution where duplication never happens, but we have small chance that some texts will be translated over and over again. Usually when someone quotes other long post, and removes some part at the end – in such case we have 1 long translation of whole original text and one long translation of shorter quoted text. Now both are cashed - if we set unique index on wt_cache then one of those will be translated each time when page is generated.

So - If users want this solution I can give the solution. Who wants it?


But , till wt_cache allows for data duplication - I advice to let cleaner and saver tables stay (you can delete all data from there). Empty tables doesn't bother anyone, and can be helpful for cleaning wt_cache from time to time. In my installation I will keep those at least till I crawl all translation sites with my spider. And probably let them stay after that too.

NLP-er 07-05-2009 10:19 PM

Quote:

Originally Posted by Dave Hybrid (Post 1843432)
We'll I tried again with your new update.

Had to get my host to run this bit as it times out in the browser.

4. Delete data duplication like described here (note this is very important - otherwise unique indexes will not be set):

They say the query is stuck on delete from cleaner...

So i am going to stick with the current update for now.

Just as I wrote:
Note that this step if very time consuming and probably you will need to connect to DB with other client that WWW. Remember - always you can use the easy way ;)

New solution is better and faster. For those who makes fresh install it is same easy as it is right now. For update - 2 ways easy: one and good one.

If you cannot handle the good one, and still want have your cache - so ok, you can stay with old version. But I think that for users it would be good if you test new solution in fresh install (if have difficulties on old one) - see it works fine, and make it official release - for all new users, who I think would like to have faster DB without data duplication.

Dave Hybrid 07-05-2009 10:22 PM

So you suggest I now release 2 versions, one for new and one for people who want to keep their old cache. I really don't think it's that much of a big deal. I appreciate your work but I think I speak for most when I say i want to keep my 1gig database that took time to grow. I cannot maintain two releases.

Dave Hybrid 07-05-2009 10:24 PM

FYI my host tried with a Mysql desktop client and it stopped on delete from cleaner.

NLP-er 07-05-2009 11:32 PM

Hello one little DB update, after which DB will be faster.
(Index will be larger, but also faster - more unique records in index)

Note that this update is independent of last one, so hope Dave will include it in official release even if the last one will wait a little.

Whole change is about index size for originaltext - it was changed from 50 to 323 (max according to mysql limitations).

For new installations - code for wt_cache is different now:
Code:

CREATE TABLE wt_cache (
id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
tl VARCHAR(10),
originaltext VARCHAR(65000),
translated TEXT,
INDEX(originaltext(323), tl)
) ENGINE = MYISAM, CHARACTER SET utf8 COLLATE utf8_bin;

For update just execute:
Code:

alter table wt_cache drop index originaltext;
create INDEX originaltext on wt_cache(originaltext(323), tl);

As I wrote it is faster. Here you have results of test before update:
MIN: 3141 MAX: 9109 AVG: 5389
MIN: 3297 MAX: 24891 AVG: 5252
MIN: 2828 MAX: 7500 AVG: 4296

MIN: 2609 MAX: 25594 AVG: 5934
MIN: 3438 MAX: 7890 AVG: 4782
MIN: 3578 MAX: 5485 AVG: 4196
TOTAL AVG: 4974

And here after update:
MIN: 2813 MAX: 28016 AVG: 5785
MIN: 2813 MAX: 5187 AVG: 4021
MIN: 3016 MAX: 5109 AVG: 4159

MIN: 2953 MAX: 6750 AVG: 4228
MIN: 2735 MAX: 7938 AVG: 4109
MIN: 3359 MAX: 7125 AVG: 4607
TOTAL AVG: 4484

Each test was generating 20 translated pages in each series. There was 3 series for each test. Each test was executed twice. Times are in ms.

Note that there is still place for some little improvements - like column tl uses max 5 signs and is set for 10... Also it is enough for tl to set encoding 'iso-8859-1' instead of utf8, so it will reserve only 5 bytes in index instead 30 like now, and index for originaltext will be longer to something like 331 letters (now upgraded have 323). But it shouldn’t give any significant speed improvements. So I leave this topic.

NLP-er 07-05-2009 11:34 PM

Quote:

Originally Posted by Dave Hybrid (Post 1843449)
FYI my host tried with a Mysql desktop client and it stopped on delete from cleaner.

Delete from cleaner should be immediate. Are you sure you established connection to DB? Can you execute any query?
Did you try execute just delete from cleaner - without other queries? Does your client needs semicolon at the end of query? Make sure you executed delete from cleaner; with semicolon. It is possible that when you did it without semicolon server still waits for rest of instruction :)

NLP-er 07-05-2009 11:43 PM

Quote:

Originally Posted by Dave Hybrid (Post 1843448)
So you suggest I now release 2 versions, one for new and one for people who want to keep their old cache. I really don't think it's that much of a big deal. I appreciate your work but I think I speak for most when I say i want to keep my 1gig database that took time to grow. I cannot maintain two releases.

No. I was suggesting to release new version, and those who wants can upgrade, those who wants can stay with old one, and new members will start form the new one - just like it happens with every update in every mod :) Was just telling you to test it on clear instance, so you will be sure that what you releasing works.

Your mod - your releases - your decisions. I gave update instrucions so it is possible to update without any data loss, and of course it is time consuming when you have such big database. I'm going right now on updated version :)

1Unreal 07-06-2009 03:37 AM

Would you be able to create something which will detect the users language. You can get it from $_SERVER['HTTP_ACCEPT_LANGUAGE']. It gives a list of their accepted languages.

Dave Hybrid 07-06-2009 10:20 AM

v2.3b

* Small change to database optimization

To upgrade;

Run this MySQL query.

Code:

alter table wt_cache drop index originaltext;
create INDEX originaltext on wt_cache(originaltext(323), tl);


Sweeks 07-06-2009 11:50 AM

Thanks for the update :) Dont know if I see a speed increase but it's functioning just fine :)

Dave Hybrid 07-06-2009 12:32 PM

Thanks for letting me know sweeks! :up:

Geraldm 07-06-2009 01:18 PM

Ok I'm a bit confused with all the different updates throughout this thread .... I'm still using v2.0 of the script. Can you please tell me the easiest way to upgrade to v2.3b while preserving the translations already in the DB?

Thanks,
Gerald.

Dave Hybrid 07-06-2009 01:20 PM

Follow the links in the main post and work through the updates, should only take a few minutes.

NLP-er 07-06-2009 02:48 PM

Quote:

Originally Posted by Sweeks (Post 1843702)
Thanks for the update :) Dont know if I see a speed increase but it's functioning just fine :)

As I show in tests results - average difference was 0,5 second - it can be hard to notice it by you, but your server will see the difference when handling several translations in same time :)

NLP-er 07-06-2009 02:53 PM

Quote:

Originally Posted by Geraldm (Post 1843732)
Ok I'm a bit confused with all the different updates throughout this thread .... I'm still using v2.0 of the script. Can you please tell me the easiest way to upgrade to v2.3b while preserving the translations already in the DB?

Thanks,
Gerald.

As wrote Dave - fallow instructions in links, als okeep in mind that you have to made it all. So you cannot just jump from 2.0 to 2.3b - you have to first made updates to 2.1, then to 2.2 and so on :) And by updates I mean DB updates, because translate.php (and plugin code) you can take just from final version.

Also note - it is wise to dissable cache before you start making any changes, and enable if after upgrate is finished. Otherwise you can have errors, because of differend DB state and dfferent translate.php instructions.

isatice 07-06-2009 04:54 PM

thanks , but could u edit it , in a way that , other languages also work ?

Dave Hybrid 07-06-2009 05:20 PM

Quote:

Originally Posted by isatice (Post 1843912)
thanks , but could u edit it , in a way that , other languages also work ?

Please explain, not sure what you mean...?

imedic 07-06-2009 05:47 PM

Great idea of a mod. Helpful for sure. I am watching this with interest. I am planning to install it in short time.

I have a suggestion from user pov:

For example: If you land on and English forum with a Polish search (on the Polish translation) you might be confuse the forum to a local one and try to post in Polish. (don't assume all users know at least a 10th of what you know. They don't. )

You can address this with an warning under the flags (big letters) that forum is translated, original content being in English.

" You are reading on a Polish translation of the original forum (in English). You can register here for free!" (for example)

Problem is you need this translated too in all languages and to appear in corespondent translations.

You may want to let admin decide what to put inside as a text because it might happen there are some subforums in Polish but he landed on the English part. So you may suggest:

"If you find this interesting you might visit our Polish section here."

With this you address a previously raised concern about the utility of this mod. Is understandable a Polish person will run from a translated site very fast but in case he knows English it might interest him. Hence you can get more users.

I am saying this because I have an International forum in English (I plan to add some 2-3 additional languages forums) but I rely also on users not native in English but interested in the subject (Aliens in my case :) )

I think best way is to make a phrase (so we can edit and customize) under flags and to be translated by Google in respective language.

I am waiting a little and take a shot at it. I need also to clear how links will be constructed under VBSEO (as I have this installed too).
Again thanks and congratulation on great idea MOD from traffic pov but also from international accessibility pov to a foreign language content.

racale 07-06-2009 06:14 PM

This product works with version 3.8.3
I tried but it does not work
thanks

Megatr0n 07-06-2009 11:23 PM

David, we still keep getting that DB error? Will a fix be released for this soon?

Dave Hybrid 07-07-2009 10:48 AM

Quote:

Originally Posted by Megatr0n (Post 1844190)
David, we still keep getting that DB error? Will a fix be released for this soon?

It's impossible to fix as far as we know, some long pages on your sites take a few mins to translate, MySQL doesn't like having a connection open that long while big pages are written to the database, nothing I can do after much trying. They will go away when your site is translated fully and do not impact the running of your site in any way. They are false warnings in effect.

Dave Hybrid 07-07-2009 10:50 AM

To combat them I set a new email in vb config and an outlook rule and now they all go to their own folder in outlook. No big deal.


All times are GMT. The time now is 08:00 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02438 seconds
  • Memory Usage 2,182KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (37)bbcode_code_printable
  • (16)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (1)pagenav_pagelinkrel
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete