function processMessage($string, $filters, $lang) { // Resolve shortened URL's to the full thing for filtering preg_match_all('/http:\\/\\/[^ $)]+/i', $string, $urls); if ($urls) { foreach ($urls[0] as $url) { if ($redirect = getRedirect($url)) { $string = str_replace($url, $redirect, $string); } } } $string = cleanString($string); if ($lang && ($aTranslation = translateString($string, $lang))) { $string = "{$aTranslation['string']} [Lang: {$aTranslation['detectedLang']}]"; } if ($filters) { foreach ($filters as $filter) { if (preg_match("/{$filter}/i", $string)) { $string = ''; break; } } } return $string; }
function ircConvertString($string) { return translateString($string, array('.' => '', '@' => '{at}', '=' => '-', ')' => '}', '(' => '{', '/' => '\\', '&' => '', '*' => '', '+' => '', '~' => '-', '#' => '', 'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'Ae', 'Å' => 'A', 'Æ' => 'AE', 'Ç' => 'C', 'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I', 'Ð' => 'D', 'Ñ' => 'N', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'Oe', '×' => 'x', 'Ø' => 'O', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'Ue', 'Ý' => 'Y', 'Þ' => '', 'ß' => 'ss', 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'ae', 'å' => 'a', 'æ' => 'ae', 'ç' => 'c', 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ð' => 'd', 'ñ' => 'n', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'oe', '÷' => '', 'ø' => 'o', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'ue', 'ý' => 'y', 'þ' => '', 'ÿ' => 'y')); }
function createChildLinks($EN_US_mlid, $EngLinkTitle, $mlid_trans, $currentLanguage) { global $db, $error_log; $to_language = array($currentLanguage['sovee_code']); $msg = "Creating children for the {$currentLanguage} version of {$EngLinkTitle} -- {$EN_US_mlid} (which is mlid={$mlid_trans})\n"; fwrite($error_log, $msg); // Walk through the EN-US children of the given menu $translatedRow = $allrows = array(); // Find all non-hidden EN-US children of a given EN-US top-level (plid=0) menu $q1 = "SELECT * from menu_links WHERE menu_name='primary-links' and plid=\"" . $EN_US_mlid . "\" \n AND hidden=0 \n AND (options regexp 's:8:\"langcode\";s:5:\"en-us\"' OR options NOT regexp '\"langcode\"')\n ORDER BY weight"; // OR (options NOT regexp '\"langcode\"' AND link_path NOT regexp '^node/') $r1 = mysql_query($q1, $db); sqlErrors($q1); $msg = "q1 = {$q1}\n\n"; $msg .= "Children of {$EngLinkTitle} are:\n"; while ($myrow = mysql_fetch_assoc($r1)) { $allrows[] = $myrow; $msg .= " " . $myrow['link_title'] . "\n"; } fwrite($error_log, $msg); foreach ($allrows as $translatedRow) { $newPlid = $translatedRow['mlid']; $originalPlid = $translatedRow['plid']; $translatedRow['plid'] = $translatedRow['p1'] = $mlid_trans; $translatedLinkTitle = trim(translateString("en-us", $currentLanguage['sovee_code'], $translatedRow['link_title'])); $msg = "Translating " . $translatedRow['link_title'] . " to " . $currentLanguage['sovee_code'] . " gives {$translatedLinkTitle}\n\n"; fwrite($error_log, $msg); if (strlen($translatedLinkTitle) < 1) { // Use English if Sovee translation fails $msg = "> > > Unable to create " . $currentLanguage['sovee_code'] . " for \"" . $translatedRow['link_title'] . "\", using English\n\n"; fwrite($error_log, $msg); $translatedLinkTitle = $currentMenuAry['link_title']; } $translatedRow['link_title'] = $translatedLinkTitle; $translatedRow['options'] = "a:2:{s:10:\"attributes\";a:1:{s:5:\"title\";s:0:\"\";}s:8:\"langcode\";s:" . strlen($currentLanguage['drupal_code']) . ":\"" . $currentLanguage['drupal_code'] . "\";}"; $EN_US_mlid = $translatedRow['mlid']; $translatedRow['mlid'] = "NULL"; $linkPath = $translatedRow['link_path']; $nodeNumber = preg_replace("/node\\//", "", $linkPath); if (is_numeric($nodeNumber)) { $msg = "Going to translate node {$nodeNumber} into " . $currentLanguage['sovee_code'] . " . . .\n"; fwrite($error_log, $msg); // Does a translation already exist for this node? $existingTranslationAry = checkForTranslatedVersion($nodeNumber, $currentLanguage['drupal_code']); $msg = "Checking return from checkForTranslatedVersion\nexistingTranslationAry = \n"; $msg .= print_r($existingTranslationAry, TRUE); fwrite($error_log, $msg); if (isset($existingTranslationAry['nid'])) { $newNodeID = $existingTranslationAry['nid']; $translatedRow['link_title'] = $existingTranslationAry['title']; $q6 = "UPDATE node SET status=1, tnid=\"{$nodeNumber}\" WHERE nid=\"{$newNodeID}\" LIMIT 1"; $r7 = mysql_query($q6, $db); $msg = "An existing " . $currentLanguage['drupal_code'] . " translation for node {$nodeNumber}, which is node {$newNodeID}, \"" . $translatedRow['link_title'] . "\"\n"; $msg .= print_r($existingTranslationAry, TRUE); $msg .= $q6 . "\n"; fwrite($error_log, $msg); } else { // A translation does NOT exist. Create one $msg = "An existing " . $currentLanguage['drupal_code'] . " translation for node {$nodeNumber} does NOT exist.\n"; $msg .= print_r($existingTranslationAry, TRUE); fwrite($error_log, $msg); $testAry = translateOneNode($nodeNumber, $to_language, "Menu Generator"); $newNodeID = $testAry['nid']; } $q4 = "DELETE FROM menu_links WHERE link_path = \"node/" . $newNodeID . "\""; $r4 = mysql_query($q4, $db); sqlErrors($q4); $translatedRow['link_path'] = "node/" . $newNodeID; // Build the INSERT statement $q3 = "INSERT INTO menu_links SET "; foreach ($translatedRow as $key => $value) { if ($value != "NULL") { $q3 .= "{$key} = \"" . addslashes($value) . "\","; } else { $q3 .= "{$key} = NULL,"; } } $q3 = rtrim($q3, ','); $r3 = mysql_query($q3, $db); $err_msg = trim(mysql_error($db)); if (strlen($err_msg) > 0) { $msg = "MYSQL_ERROR: {$err_msg}\nQuery = {$q1}\n"; echo $msg; fwrite($error_log, $msg); } $msg1 = "q3 = {$q3}\n"; $r5 = mysql_query("SELECT LAST_INSERT_ID() as mlid", $db); // Get the mlid of the newly-inserted row while ($mtmp = mysql_fetch_assoc($r5)) { $mlid_last = $mtmp['mlid']; } $q4 = "UPDATE menu_links SET p2 = mlid WHERE mlid=\"" . $mlid_last . "\" LIMIT 1"; $msg1 .= "Q4 = {$q4}\n\n"; $r4 = mysql_query($q4, $db); sqlErrors($q4); fwrite($error_log, $msg1); // End of if (is_numeric($nodeNumber)) //yes// } else { // Handle link_path without node identifier // ADD NEW CODE FOR LINK_PATH $msg = "Looking for link_paths without node identifiers in " . $currentLanguage['drupal_code'] . "\n\n"; fwrite($error_log, $msg); $q5a = "SELECT mlid, link_title from menu_links where link_path = \"{$linkPath}\"\n AND menu_name = 'primary-links'\n AND options regexp '\"langcode\";s:" . strlen($currentLanguage['drupal_code']) . ":\"" . $currentLanguage['drupal_code'] . "\";'\n ORDER BY hidden ASC\n\t\t\tLIMIT 1"; // We need only one value, take the first visible one, if multiple are present $r5a = mysql_query($q5a, $db); sqlErrors($q5a); if (mysql_num_rows($r5a) > 0) { while ($m5a = mysql_fetch_assoc($r5a)) { $thisMlid = $m5a['mlid']; $thisLinkTitle = $m5a['link_title']; $msg = "Found {$thisLinkTitle} at mlid={$thisMlid}\n"; fwrite($error_log, $msg); } $q6a = "UPDATE menu_links SET plid='" . $mlid_trans . "', p1='" . $mlid_trans . "', hidden='0', \n\t\t\t\tlink_title = '" . $translatedLinkTitle . "'\n WHERE mlid='" . $thisMlid . "'"; $msg = "q6a = {$q6a}\n"; fwrite($error_log, $msg); $r6a = mysql_query($q6a, $db); sqlErrors($q6a); } else { //INSERT NEW ROW, GRAB NEW MLID, POPULATE p1 $q6a = "INSERT INTO menu_links SET\n\t\t\tmenu_name = 'primary-links',\n\t\t\tmlid = NULL,\n\t\t\tplid = '" . $mlid_trans . "',\n\t\t\tlink_path = '" . $linkPath . "',\n\t\t\trouter_path = '" . $translatedRow['router_path'] . "',\n\t\t link_title = '" . $translatedLinkTitle . "',\n\t\t\toptions = 'a:2:{s:10:\"attributes\";a:1:{s:5:\"title\";s:0:\"\";}s:8:\"langcode\";s:" . strlen($currentLanguage['drupal_code']) . ":\"" . $currentLanguage['drupal_code'] . "\";}',\n\t\t\tmodule = '" . $translatedRow['module'] . "', \n\t\t\thidden = '0',\n\t\t\texternal = '" . $translatedRow['external'] . "',\n\t\t\thas_children = '" . $translatedRow['has_children'] . "',\n expanded = '" . $translatedRow['expanded'] . "',\n weight = '" . $translatedRow['weight'] . "',\n depth = '" . $translatedRow['depth'] . "',\n customized = '" . $translatedRow['customized'] . "',\n\t\t\tp1 = '" . $mlid_trans . "',\n\t\t\tupdated = '0'"; $msg = "q6a = {$q6a}\n"; fwrite($error_log, $msg); $r6a = mysql_query($q6a, $db); sqlErrors($q6a); $r7 = mysql_query("SELECT LAST_INSERT_ID() as mlid", $db); // Get the mlid of the newly-inserted row while ($mtmp = mysql_fetch_assoc($r7)) { $mlid_last = $mtmp['mlid']; } $q6b = "UPDATE menu_links SET p1 = mlid WHERE mlid=\"" . $mlid_last . "\" LIMIT 1"; $r6b = mysql_query($q6b, $db); $msg = "q6b = {$q6b}\n"; sqlErrors($q6b); } } // End of if (is_numeric($nodeNumber)) } // End of foreach($allrows as $translatedRow) }
function ircConvertString($string) { return translateString($string, array('.' => '', '@' => '{at}', 'ä' => 'ae', 'ü' => 'ue', 'ö' => 'oe', 'Ä' => 'Ae', 'Ü' => 'Ue', 'Ö' => 'Oe', '=' => '-', ')' => '}', '(' => '{', '/' => '\\', '&' => '', '*' => '', '+' => '', '~' => '-', '#' => '')); }
#!/usr/bin/php <?php Mb_Internal_Encoding('UTF-8'); $loc = "UTF-8"; putenv("LANG={$loc}"); $loc = setlocale(LC_ALL, $loc); $token = getSoveeAuthToken(); $stringTest = translateString("en-us", "it-it", "This is my string"); echo "Stringtest = |{$stringTest}|\n"; $fragment = "<div>this is a test</div>"; $fragmentTest = translateFrag($fragment, 0, "foo", "it-it"); print_r($fragmentTest); # =================================================================== function getSoveeAuthToken() { $data = array('username' => '*****@*****.**', 'password' => 'bill3cat', 'customer' => 'SonoSite'); $ch = curl_init(); $url = "https://auth.sovee.com/auth/login.txt"; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE); curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE); curl_setopt($ch, CURLOPT_FORBID_REUSE, TRUE); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_PROXY, "itproxy.sonosite.com"); curl_setopt($ch, CURLOPT_PROXYPORT, "3128"); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); curl_setopt($ch, CURLOPT_COOKIEJAR, "/home/cjacks/translate/cookies"); curl_setopt($ch, CURLOPT_COOKIEFILE, "/home/cjacks/translate/cookies");
function eht($str) { echo htmlencode(translateString($str)); }