Easy AdSense. */ /* Copyright (C) 2008 www.thulasidas.com This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ define('minmatch', 89) ; if (!class_exists("ezTran") && !class_exists("PO")) { class PO { // an id-str pair with attributes var $num, $id, $str, $tranId, $tranVal, $keyId, $keyVal ; function PO($id, $str) { $this->id = (string) $id ; $this->str = (string) $str ; $this->tranVal = minmatch ; $this->keyVal = minmatch ; } // Returns a text-area string of the Id function textId() { $ht = round(strlen($this->id)/52 + 1) * 25 ; $col = 'background-color:#f5f5f5;' ; if ($this->keyVal > minmatch+1) { $col = "background-color:#ffc;border: solid 1px #f00" ; $tit = 'onmouseover = "Tip(\'Another similar string: ' . htmlspecialchars('
' . addcslashes($this->keyId, "\n") . '
', ENT_QUOTES) . 'exists. Please alert the author.\',WIDTH, 300)" ' . 'onmouseout="UnTip()"'; } $s = '  ' ; return $s ; } function textStr() { $ht = round(strlen($this->id)/52 + 1) * 25 ; if ($this->tranVal > minmatch+1){ $col = "background-color:#fdd;border: solid 1px #f00" ; $tit = 'onmouseover = "Tip(\'Using the translation for a similar string: ' . htmlspecialchars('
' . addcslashes($this->tranId, "\n") . '
', ENT_QUOTES) . 'Please check carefully.\',WIDTH, 300)" ' . 'onmouseout="UnTip()"'; } $s = '
' ; return $s ; } } class ezTran { var $status, $error ; function ezTran() { $this->status = '' ; $this->error = '' ; if ($_POST['savePot']) { $file = $_POST['potFile'] ; $str = $_POST['potStr'] ; header('Content-Disposition: attachment; filename="' . $file .'"'); header("Content-Transfer-Encoding: ascii"); header('Expires: 0'); header('Pragma: no-cache'); ob_start() ; print stripslashes(htmlspecialchars_decode($str, ENT_QUOTES)) ; ob_end_flush() ; $this->status = '
Pot file: ' . $file . ' was saved.
' ; exit(0) ; } if ($_POST['mailPot']) { if (!class_exists("phpmailer")) { require_once(ABSPATH.'wp-includes/class-phpmailer.php'); } $mail = new PHPMailer(); $mail->From = get_bloginfo('admin_email') ; $mail->FromName = get_bloginfo('name') ; $mail->AddAddress('Manoj@Thulasidas.com', "Manoj Thulasidas") ; $mail->CharSet = get_bloginfo('charset'); $mail->Mailer = 'php'; $mail->SMTPAuth = false; $mail->Subject = $file; $file = $_POST['potFile'] ; $str = stripslashes($_POST['potStr']) ; $str = str_replace("\'", "'", $str) ; $mail->AddStringAttachment($str,$file) ; $pos1 = strpos($str, "msgstr") ; $pos2 = strpos($str, "msgid", $pos1) ; $head = substr($str, 0, $pos2) ; $mail->Body = $head ; if ($mail->Send()) $this->status = '
Pot file: ' . $file . ' was sent.
' ; else $this->error = '
Error: ' . $mail->ErrorInfo . '
' ; } } // Return the contents of all PHP files in the dir specified function getFileContents($dir="") { if ($dir == "") $dir = dirname(__FILE__) ; $files = glob($dir . '/*.php') ; $page = "" ; foreach ($files as $f) { $page .= file_get_contents($f, FILE_IGNORE_NEW_LINES) ; } return $page ; } // Percentage Levenshtein distance function levDist(&$s1, &$s2) { similar_text($s1, $s2, $p) ; return round($p) ; } // Get the closest existing translation keys, and the recursivley closest in the // key set function getClose(&$mo, &$POs){ foreach ($POs as $n => $po){ $s1 = $po->id ; $l1 = strlen($s1); if (strlen($po->str) == 0) { if (!empty($mo)) foreach ($mo as $mn => $mk) { $s2 = $mn ; $result = $this->levDist($s1, $s2) ; if ($result > $po->tranVal) { $po->tranVal = $result ; $po->tranId = $mn ; $po->str = $mk->translations[0] ; } } } foreach ($POs as $n2 => $po2){ if ($n != $n2){ $s2 = $po2->id ; $result = $this->levDist($s1, $s2) ; if ($result > $po2->keyVal) { $po->keyVal = $result ; $po->keyId = $po2->id ; $po2->keyVal = $result ; $po2->keyId = $po->id ; } } } } } // Get the strings that look like translation keys function getTranPOs(&$contents, &$mo, $domain, &$POs) { preg_match_all("#_[_e].*\([\'\"](.+)[\'\"]\s*,\s*[\'\"]" . $domain ."[\'\"]#", $contents, $matches) ; $keys = array_unique($matches[1]) ; $keys = str_replace(array("\'", '\"', '\n'), array("'", '"', "\n"), $keys) ; foreach ($keys as $n => $k) { $v = $mo[$k] ; $t = $v->translations[0] ; $po = new PO($k, $t) ; $po->num = $n ; array_push($POs, $po) ; } $this->getClose($mo, $POs) ; } // Make a POT string from ids and msgs function mkPot(&$POs, $msg){ $pot = '' ; $pot .= '# This file was generated by Easy Translator -- a WordPress plugin translator # Your Name: ' . $msg["name"] . ' # Your Email: ' . $msg["email"] . ' # Your Website: ' . $msg["blog"] . ' # Your URL: ' . $msg["url"] . ' # Your Locale: ' . $msg["locale"] . ' # Your Language: ' . $msg["lang"] . ' #, fuzzy msgid "" msgstr "" "Project-Id-Version: Easy AdSenser\n" "PO-Revision-Date: ' . current_time('mysql') . '\n" "Last-Translator: ' . $msg['name'] . ' <' . $msg['email'] . '>\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=' . $msg['charset'] . '\n" "Content-Transfer-Encoding: 8bit\n" ' ; foreach ($POs as $n => $po) { $pot .= "msgid " . '"' . addcslashes($po->id, "\n\r\"") . '"' . "\n" ; $t = $msg[$po->num] ; $pot .= "msgstr " . '"' . addcslashes($t, "\n\r") . '"' . "\n\n" ; } return $pot ; } // Prints out the admin page function printAdminPage() { $locale = get_locale(); $made = isset($_POST['make']) ; $saving = isset($_POST['save']) ; ?>

Easy Translator

Easy AdSense Translation Interface

Error:' . 'Sorry, Easy Translator works only on WP2.8+

' ; return ; } $mo = array($l10n[$domain]->entries) ; $s = $this->getFileContents() ; $parent = dirname(__FILE__) . '/..' ; $s .= $this->getFileContents($parent) ; $POs = array() ; $this->getTranPOs($s, $mo[0], $domain, $POs) ; if ($made) { $pot = htmlspecialchars($this->mkPot($POs, $_POST), ENT_QUOTES) ; } else { global $current_user; get_currentuserinfo(); $pot = '' ; $pot .= '
Your Name:
' . 'user_lastname . '" />
' . "\n" ; $pot .= '
Your Email:
' . '
' . "\n" ; $pot .= '
Your Website:
' . '' . "\n
" ; $pot .= '
Your URL:
' . '' . "\n
" ; $pot .= '
Your Locale:
' . '
' . "\n" ; $pot .= '
Your Language:
' . '
' . "\n" ; $pot .= '
Character Set:
' . '' . "\n

" ; $pot .= '
' ; $pot .= '
' . 'English (en_US)
' ; $pot .= '
' . 'Your Language (' . $locale . ')
' ; $pot .= '
' ; foreach ($POs as $n => $po) { $pot .= $po->textId() . "\n" . $po->textStr() . "\n\n" ; } } $makeStr = '
 
' . $this->status . $this->error ; $saveStr = '
   
' . $this->status . $this->error ; if ($made) { ?>
If you are happy with the POT file as below, please save it or email it to the author. If not, edit it further.
' ; echo '' ; echo $saveStr ; echo "\n" . '
' . $pot . '
' ; } else { ?>
Add or modify translation for your language .
Enter the translated strings in the text boxes below and hit the "Display POT File" button.