Пример #1
0
 public function Save($blnForceInsert = false, $blnForceUpdate = false)
 {
     $this->intSuggestionWordCount = NarroString::WordCount($this->strSuggestionValue);
     $this->intSuggestionCharCount = mb_strlen($this->strSuggestionValue);
     $this->strSuggestionValueMd5 = md5($this->strSuggestionValue);
     if (!isset($this->blnIsImported)) {
         $this->blnIsImported = false;
     }
     if (!$this->__blnRestored || $blnForceInsert) {
         $this->dttCreated = QDateTime::Now();
     } else {
         $this->dttModified = QDateTime::Now();
     }
     parent::Save($blnForceInsert, $blnForceUpdate);
     /**
      * Update all context infos with the has suggestion property
      */
     $arrContextInfo = NarroContextInfo::QueryArray(QQ::AndCondition(QQ::Equal(QQN::NarroContextInfo()->Context->TextId, $this->intTextId), QQ::Equal(QQN::NarroContextInfo()->LanguageId, $this->intLanguageId), QQ::Equal(QQN::NarroContextInfo()->HasSuggestions, 0)));
     foreach ($arrContextInfo as $objOneContextInfo) {
         $objOneContextInfo->HasSuggestions = 1;
         $objOneContextInfo->Modified = QDateTime::Now();
         try {
             $objOneContextInfo->Save();
         } catch (Exception $objEx) {
             NarroLogger::LogWarn($objEx->getMessage());
         }
     }
 }
Пример #2
0
 public function GetControlHtml()
 {
     $strLogContents = '';
     foreach (NarroLog::QueryArray(QQ::AndCondition(QQ::Equal(QQN::NarroLog()->ProjectId, $this->intProjectId), QQ::Equal(QQN::NarroLog()->LanguageId, $this->intLanguageId), QQ::GreaterThan(QQN::NarroLog()->Date, $this->dttStart))) as $objLogEntry) {
         switch ($objLogEntry->Priority) {
             case NarroLog::PRIORITY_INFO:
                 $strLogContents .= '<div class="info"';
                 break;
             case NarroLog::PRIORITY_WARN:
                 $strLogContents .= '<div class="warning"';
                 break;
             case NarroLog::PRIORITY_ERROR:
                 $strLogContents .= '<div class="error"';
                 break;
             default:
                 $strLogContents .= '<div';
         }
         $strLogContents .= sprintf('title="%s">%s</div>', $objLogEntry->Date, nl2br(NarroString::HtmlEntities($objLogEntry->Message)));
     }
     $this->strText = sprintf('<div class="ui-accordion ui-widget ui-helper-reset ui-accordion-icons">
             <h3 class="ui-accordion-header ui-helper-reset ui-state-default ui-state-active ui-corner-top">
             <span class="ui-icon ui-icon-triangle-1-s"></span>
             <a>%s</a>
             </h3>
             <div class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content-active" style="max-height:300px;overflow:auto">
             %s
             </div>
             </div>', t('Operation log'), $strLogContents);
     return parent::GetControlHtml();
 }
 public function ExportFile($strTemplate, $strTranslatedFile)
 {
     if ($strTemplateFileContents = file_get_contents($strTemplate)) {
         $arrTemplate = array();
         if (preg_match_all('/([^$]+)\\$([^\\s]+)\\s*=\\s*([\']?.*[\']?);(.*)/m', $strTemplateFileContents, $arrTemplateMatches)) {
             foreach ($arrTemplateMatches[2] as $intKey => $strIdentifier) {
                 if (trim(preg_replace('/^\'(.*)\'$/', '\\1', $arrTemplateMatches[3][$intKey]))) {
                     $strText = preg_replace('/^\'(.*)\'$/', '\\1', $arrTemplateMatches[3][$intKey]);
                     $strContext = $arrTemplateMatches[1][$intKey] . $arrTemplateMatches[2][$intKey] . $arrTemplateMatches[4][$intKey];
                     $objNarroContextInfo = $this->GetContextInfo($strText, trim($strContext));
                     if ($objNarroContextInfo->ValidSuggestionId) {
                         /**
                          * @todo replace the following code with a replacement of the full line
                          */
                         $strNewBlock = NarroString::Replace("= '" . $strText . "'", "= '" . $objNarroContextInfo->ValidSuggestion->SuggestionValue . "'", $arrTemplateMatches[0][$intKey], 1);
                         $strTemplateFileContents = str_replace($arrTemplateMatches[0][$intKey], $strNewBlock, $strTemplateFileContents);
                     }
                 }
             }
             file_put_contents($strTranslatedFile, $strTemplateFileContents);
         }
     } else {
         NarroLogger::LogError(sprintf('Cannot open file "%s".', $strFileToImport));
     }
 }
Пример #4
0
 public function Save($blnForceInsert = false, $blnForceUpdate = false)
 {
     $this->intTextWordCount = NarroString::WordCount($this->strTextValue);
     $this->intTextCharCount = strlen($this->strTextValue);
     $this->strTextValueMd5 = md5($this->strTextValue);
     if (!$this->__blnRestored || $blnForceInsert) {
         $this->dttCreated = QDateTime::Now();
     } else {
         $this->dttModified = QDateTime::Now();
     }
     parent::Save($blnForceInsert, $blnForceUpdate);
 }
Пример #5
0
 public function colMessage_Render(NarroLog $objLog)
 {
     switch ($objLog->Priority) {
         case NarroLog::PRIORITY_INFO:
             $strMessage = '<div class="info"';
             break;
         case NarroLog::PRIORITY_WARN:
             $strMessage = '<div class="warning"';
             break;
         case NarroLog::PRIORITY_ERROR:
             $strMessage = '<div class="error"';
             break;
         default:
             $strMessage = '<div';
     }
     return sprintf('%s title="%s">%s</div>', $strMessage, $objLog->Date, nl2br(NarroString::HtmlEntities($objLog->Message)));
 }
Пример #6
0
 public function lblContextInfo_Create()
 {
     if (!$this->lblContextInfo) {
         $this->lblContextInfo = new QLabel($this);
         $this->lblContextInfo->CssClass = 'instructions ctxinfo';
         $this->lblContextInfo->TagName = 'div';
         $this->lblContextInfo->DisplayStyle = QDisplayStyle::None;
         if (QApplication::QueryString('p')) {
             $this->lblContextInfo->Text = sprintf('%s<br /><span>%s</span>', $this->objContextInfo->Context->File->FilePath, NarroString::HtmlEntities($this->objContextInfo->Context->Context));
         } else {
             $this->lblContextInfo->Text = sprintf('<b>%s</b>%s<br /><span>%s</span>', $this->objContextInfo->Context->Project->ProjectName, $this->objContextInfo->Context->File->FilePath, NarroString::HtmlEntities($this->objContextInfo->Context->Context));
         }
         $this->lblContextInfo->HtmlEntities = false;
         if ($this->objContextInfo->Context->Comment) {
             $this->lblContextInfo->Text .= '<br />' . nl2br(str_replace(array('<!--', '-->'), array('', ''), NarroString::HtmlEntities($this->objContextInfo->Context->Comment)));
         }
     }
 }
 /**
  * This function looks for accesskey entries and creates po style texts, e.g. &File
  * @param array $arrTexts an array with context as keys and texts as values
  */
 public function GetAccessKeys($arrTexts)
 {
     $arrTexts = parent::GetAccessKeys($arrTexts);
     foreach ($arrTexts as $strContext => $objEntity) {
         if (preg_match('/&([a-z0-9])/i', html_entity_decode($objEntity->Value), $arrMatches)) {
             $objEntity->AccessKey = $arrMatches[1];
             $arrTexts[$strContext]->Value = NarroString::Replace($arrMatches[0], $arrMatches[1], $objEntity->Value, 1);
         }
     }
     return $arrTexts;
 }
 public function colText_Render(NarroTextComment $objComment)
 {
     return str_replace('?l=' . QApplication::$TargetLanguage->LanguageCode, '?l=' . $objComment->Language->LanguageCode, NarroLink::Translate(0, '', NarroTranslatePanel::SHOW_ALL, "'" . $objComment->Text->TextValue . "'", 0, 0, 10, 0, 0, NarroString::HtmlEntities($objComment->Text->TextValue)));
 }
 /**
  * A translation here consists of the project, file, text, translation, context, plurals, approval, ignore equals
  *
  * @param string $strOriginal the original text
  * @param string $strOriginalAccKey access key for the original text
  * @param string $strTranslation the translated text from the import file (can be empty)
  * @param string $strOriginalAccKey access key for the translated text
  * @param string $strContext the context where the text/translation appears in the file
  * @param string $intPluralForm if this is a plural, what plural form is it (0 singular, 1 plural form 1, and so on)
  * @param string $strComment a comment from the imported file
  *
  * @return string valid suggestion
  */
 protected function GetTranslation($strOriginal, $strOriginalAccKey = null, $strOriginalAccKeyPrefix = null, $strTranslation, $strTranslationAccKey = null, $strContext, $strComment = null)
 {
     /**
      * The contexts are trimmed at import to avoid useless white space contexts, so we need to trim it when searching for it as well
      */
     $strContext = trim($strContext);
     if ($strContext != '') {
         $objNarroContextInfo = NarroContextInfo::QuerySingle(QQ::AndCondition(QQ::Equal(QQN::NarroContextInfo()->Context->ProjectId, $this->objProject->ProjectId), QQ::Equal(QQN::NarroContextInfo()->Context->FileId, $this->objFile->FileId), QQ::Equal(QQN::NarroContextInfo()->Context->Active, 1), QQ::Equal(QQN::NarroContextInfo()->Context->File->Active, 1), QQ::Equal(QQN::NarroContextInfo()->Context->TextAccessKey, $strOriginalAccKey), QQ::Equal(QQN::NarroContextInfo()->Context->ContextMd5, md5($strContext)), QQ::Equal(QQN::NarroContextInfo()->Context->Text->TextValueMd5, md5($strOriginal)), QQ::Equal(QQN::NarroContextInfo()->LanguageId, $this->objTargetLanguage->LanguageId)));
     } else {
         $objNarroContextInfo = NarroContextInfo::QuerySingle(QQ::AndCondition(QQ::Equal(QQN::NarroContextInfo()->Context->ProjectId, $this->objProject->ProjectId), QQ::Equal(QQN::NarroContextInfo()->Context->FileId, $this->objFile->FileId), QQ::Equal(QQN::NarroContextInfo()->Context->Active, 1), QQ::Equal(QQN::NarroContextInfo()->Context->File->Active, 1), QQ::Equal(QQN::NarroContextInfo()->Context->TextAccessKey, $strOriginalAccKey), QQ::Equal(QQN::NarroContextInfo()->Context->Text->TextValueMd5, md5($strOriginal)), QQ::Equal(QQN::NarroContextInfo()->LanguageId, $this->objTargetLanguage->LanguageId)));
     }
     if ($objNarroContextInfo instanceof NarroContextInfo) {
         $this->objCurrentContext = $objNarroContextInfo;
         $strSuggestionValue = $this->GetExportedSuggestion($objNarroContextInfo);
         if ($strSuggestionValue !== false) {
             $arrResult = QApplication::$PluginHandler->ExportSuggestion($strOriginal, $strSuggestionValue, $strContext, $this->objFile, $this->objProject);
             if ($arrResult[1] != '' && $arrResult[0] == $strOriginal && $arrResult[2] == $strContext && $arrResult[3] == $this->objFile && $arrResult[4] == $this->objProject) {
                 $strSuggestionValue = $arrResult[1];
             } else {
                 NarroLogger::LogWarn(sprintf('The plugin "%s" returned an unexpected result while processing the suggestion "%s": %s', QApplication::$PluginHandler->CurrentPluginName, $strSuggestionValue, join(';', $arrResult)));
             }
             if (!is_null($strOriginalAccKey) && !is_null($strOriginalAccKeyPrefix)) {
                 /**
                  * @todo don't export if there's no valid access key
                  */
                 $strTextWithAccKey = NarroString::Replace($objNarroContextInfo->SuggestionAccessKey, $strOriginalAccKeyPrefix . $objNarroContextInfo->SuggestionAccessKey, $strSuggestionValue, 1);
                 return $strTextWithAccKey;
             } else {
                 return $strSuggestionValue;
             }
         } else {
             // NarroLogger::LogDebug(sprintf('No translation found for the text "%s", while searching for context "%s"', $strOriginal, $strContext));
             return '';
         }
     } else {
         NarroLogger::LogError(sprintf('No context found for the text "%s", while searching for context "%s"', $strOriginal, $strContext));
         return '';
     }
 }
 /**
  * A translation here consists of the project, file, text, translation, context, plurals, approval, ignore equals
  *
  * @param string $strOriginal the original text
  * @param string $strOriginalAccKey access key for the original text
  * @param string $strTranslation the translated text from the import file (can be empty)
  * @param string $strOriginalAccKey access key for the translated text
  * @param string $strContext the context where the text/translation appears in the file
  * @param string $intPluralForm if this is a plural, what plural form is it (0 singular, 1 plural form 1, and so on)
  * @param string $strComment a comment from the imported file
  *
  * @return string valid suggestion
  */
 protected function GetTranslation($strOriginal, $strOriginalAccKey = null, $strOriginalAccKeyPrefix = null, $strTranslation, $strTranslationAccKey = null, $strContext, $strComment = null)
 {
     $objNarroContextInfo = NarroContextInfo::QuerySingle(QQ::AndCondition(QQ::Equal(QQN::NarroContextInfo()->Context->ProjectId, $this->objProject->ProjectId), QQ::Equal(QQN::NarroContextInfo()->Context->FileId, $this->objFile->FileId), QQ::Equal(QQN::NarroContextInfo()->Context->ContextMd5, md5(trim($strContext))), QQ::Equal(QQN::NarroContextInfo()->Context->Text->TextValueMd5, md5($strOriginal)), QQ::Equal(QQN::NarroContextInfo()->LanguageId, $this->objTargetLanguage->LanguageId)));
     if ($objNarroContextInfo instanceof NarroContextInfo) {
         $strSuggestionValue = $this->GetExportedSuggestion($objNarroContextInfo);
         $arrResult = QApplication::$PluginHandler->ExportSuggestion($strOriginal, $strSuggestionValue, $strContext, $this->objFile, $this->objProject);
         if ($arrResult[1] != '' && $arrResult[0] == $strOriginal && $arrResult[2] == $strContext && $arrResult[3] == $this->objFile && $arrResult[4] == $this->objProject) {
             $strSuggestionValue = $arrResult[1];
         } else {
             NarroLogger::LogWarn(sprintf('The plugin "%s" returned an unexpected result while processing the suggestion "%s": %s', QApplication::$PluginHandler->CurrentPluginName, $strTranslation, $strTranslation));
         }
         if (!is_null($strOriginalAccKey) && !is_null($strOriginalAccKeyPrefix)) {
             /**
              * @todo don't export if there's no valid access key
              */
             $strTextWithAccKey = NarroString::Replace($objNarroContextInfo->SuggestionAccessKey, $strOriginalAccKeyPrefix . $objNarroContextInfo->SuggestionAccessKey, $strSuggestionValue, 1);
             return $strTextWithAccKey;
         } else {
             return $strSuggestionValue;
         }
     } else {
         /**
          * leave it untranslated
          */
         return $strOriginal;
     }
 }
 public function colText_Render(NarroContextInfo $objContextInfo)
 {
     return str_replace('?l=' . QApplication::$TargetLanguage->LanguageCode, '?l=' . $objContextInfo->Language->LanguageCode, NarroLink::Translate($objContextInfo->Context->ProjectId, '', NarroTranslatePanel::SHOW_ALL, "'" . $objContextInfo->ValidSuggestion->Text->TextValue . "'", 0, 0, 10, 0, 0, NarroString::HtmlEntities($objContextInfo->ValidSuggestion->Text->TextValue)));
 }
 public function ExportFile($strTemplateFile, $strTranslatedFile)
 {
     $hndTranslatedFile = @fopen($strTranslatedFile, 'w');
     if (!$hndTranslatedFile) {
         throw new Exception(sprintf('Can\'t open file "%s" for writing', $strTranslatedFile));
     }
     $intTotalToProcess = NarroUtils::CountFileLines($strTemplateFile);
     /**
      * get all the texts and contexts from the template file, including the file line
      */
     $arrTexts = $this->FileToArray($strTemplateFile, $this->objSourceLanguage->LanguageCode, true);
     // NarroLogger::LogDebug(sprintf('Starting to process file "%s" (%d texts), the result is written to "%s".', $strTemplateFile, $intTotalToProcess, $strTranslatedFile));
     $intFileLineNr = 0;
     foreach ($arrTexts as $strContext => $arrTextInfo) {
         $strText = $arrTextInfo[0];
         $strTextAccKey = $arrTextInfo[1];
         $strTextAccKeyPrefix = $arrTextInfo[2];
         $strFileLine = $arrTextInfo[3];
         $intFileLineNr++;
         $arrColumn = preg_split('/\\t/', $strFileLine);
         /**
          * Unset a number before language code
          */
         $arrColumn[8] = '';
         /**
          * create a copy for the translated line, we'll just replace lang code, the number on column 8 and the text with the translation
          */
         $arrTranslatedColumn = $arrColumn;
         $arrTranslatedColumn[8] = 0;
         $arrTranslatedColumn[9] = 'ro';
         $objNarroContextInfo = $this->GetContextInfo($strText, $strContext);
         if (!$objContextInfo) {
             // NarroLogger::LogDebug('No context info found, trying database');
             $objContextInfo = NarroContextInfo::QueryArray(QQ::AndCondition(QQ::Equal(QQN::NarroContextInfo()->Context->FileId, $this->objFile->FileId), QQ::Equal(QQN::NarroContextInfo()->LanguageId, $this->objTargetLanguage->LanguageId), QQ::Equal(QQN::NarroContextInfo()->Context->Text->TextValueMd5, md5($strText)), QQ::Equal(QQN::NarroContextInfo()->Context->ContextMd5, md5($strContext))));
         }
         /**
          * the original texts are used if no suggestion is found, so we export only approved texts
          */
         if ($objNarroContextInfo instanceof NarroContextInfo) {
             $strSuggestionValue = $this->GetExportedSuggestion($objNarroContextInfo);
         } else {
             // NarroLogger::LogDebug('No context info found, skipping');
             continue;
         }
         if (!isset($strSuggestionValue) || !$strSuggestionValue) {
             continue;
         }
         if ($objNarroContextInfo->Context->TextAccessKey != '') {
             if ($objNarroContextInfo->ValidSuggestionId && $objNarroContextInfo->SuggestionAccessKey != '') {
                 $strSuggestionValue = NarroString::Replace($objNarroContextInfo->SuggestionAccessKey, $strTextAccKeyPrefix . $objNarroContextInfo->SuggestionAccessKey, $strSuggestionValue, 1);
             } else {
                 $strSuggestionValue = $strTextAccKeyPrefix . $strSuggestionValue;
             }
         }
         $arrTranslatedColumn[10] = str_replace(array("\n", "\r"), array("", ""), $strSuggestionValue);
         preg_match_all('/\\\\"/', $strText, $arrEscOrigMatches);
         preg_match_all('/\\\\"/', $strSuggestionValue, $arrEscTransMatches);
         if (isset($arrEscOrigMatches[0]) && count($arrEscTransMatches[0]) % 2 != 0) {
             NarroLogger::LogWarn(sprintf('Warning! The translated text "%s" has unclosed double quotes.', $strSuggestionValue));
             continue;
         }
         fwrite($hndTranslatedFile, join("\t", $arrColumn));
         fwrite($hndTranslatedFile, join("\t", $arrTranslatedColumn));
     }
     fclose($hndTranslatedFile);
     if (filesize($strTranslatedFile) == 0) {
         unlink($strTranslatedFile);
     } else {
         chmod($strTranslatedFile, 0666);
     }
 }
Пример #13
0
                                <br />', NarroString::HtmlEntities($objTextComment->Text->TextValue));
                            foreach ($arrProjects as $intProjectId => $strProjectName) {
                                $strProjectLink = __HTTP_URL__ . __VIRTUAL_DIRECTORY__ . __SUBDIRECTORY__ . '/' . NarroLink::ProjectTextList($intProjectId, NarroTranslatePanel::SHOW_ALL, $objTextComment->Text->TextValue);
                                $arrProjectLinks[] = sprintf(t('<a href="%s">%s</a>'), $strProjectLink, $strProjectName);
                            }
                            $strDescription .= join(', ', $arrProjectLinks) . '</small>';
                        }
                    } else {
                        continue;
                    }
                    $objItem = new QRssItem(strlen($objTextComment->CommentText) > 124 ? substr($objTextComment->CommentText, 0, 124) . '...' : $objTextComment->CommentText, $strContextLink);
                    $objItem->Description = $strDescription;
                    $objItem->PubDate = new QDateTime($objTextComment->Created);
                    $objItem->Author = $objTextComment->User->RealName;
                    /**
                     * Damn Google Reader doesn't care about PubDate, so we need this
                     */
                    $objItem->Guid = NarroString::HtmlEntities($strContextLink);
                    $objItem->GuidPermaLink = true;
                    $objRssFeed->AddItem($objItem);
                }
            }
            $objRssFeed->Language = strtolower(QApplication::$TargetLanguage->LanguageCode);
            $objRssFeed->Image = new QRssImage(__HTTP_URL__ . __VIRTUAL_DIRECTORY__ . __SUBDIRECTORY__ . '/assets/images/narro.png', t('Narro - Translate, we\'re open!'), __HTTP_URL__ . __VIRTUAL_DIRECTORY__ . __SUBDIRECTORY__ . '/index.php');
            QApplication::$Cache->save($objRssFeed, $strCacheId, array(), 3600);
        }
        $objRssFeed->Run();
        break;
    default:
        exit;
}