/**
  * 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, $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->ContextMd5, md5($strContext)), QQ::Equal(QQN::NarroContextInfo()->Context->Text->TextValueMd5, md5($strOriginal)), QQ::Equal(QQN::NarroContextInfo()->LanguageId, $this->objTargetLanguage->LanguageId), QQ::IsNotNull(QQN::NarroContextInfo()->ValidSuggestionId)));
     if ($objNarroContextInfo instanceof NarroContextInfo) {
         return $objNarroContextInfo->ValidSuggestion->SuggestionValue;
     } else {
         return $strOriginal;
     }
 }
 /**
  * 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;
     }
 }
Example #4
0
 protected function UpdateProjectProgress($intLanguageId, $strColumn, $intValue)
 {
     $objProjectProgress = NarroProjectProgress::LoadByProjectIdLanguageId($this->ProjectId, $intLanguageId);
     $blnChanged = false;
     if (!$objProjectProgress instanceof NarroProjectProgress) {
         $objProjectProgress = new NarroProjectProgress();
         $objProjectProgress->LanguageId = $intLanguageId;
         $objProjectProgress->ProjectId = $this->ProjectId;
         $objProjectProgress->TotalTextCount = 0;
         $objProjectProgress->ApprovedTextCount = 0;
         $objProjectProgress->FuzzyTextCount = 0;
         $objProjectProgress->ProgressPercent = 0;
         $objProjectProgress->Active = $this->Active;
         $objProjectProgress->LastModified = QDateTime::Now();
         $blnChanged = true;
     }
     // Nothing changed
     if (!$blnChanged && $objProjectProgress->{$strColumn} == $intValue) {
         return true;
     }
     $objProjectProgress->{$strColumn} = $intValue;
     if ($objProjectProgress->TotalTextCount) {
         $objProjectProgress->ProgressPercent = floor($objProjectProgress->ApprovedTextCount * 100 / $objProjectProgress->TotalTextCount);
     } else {
         $objProjectProgress->ProgressPercent = 0;
     }
     $objLastContextInfo = NarroContextInfo::QuerySingle(QQ::AndCondition(QQ::Equal(QQN::NarroContextInfo()->Context->ProjectId, $this->intProjectId), QQ::Equal(QQN::NarroContextInfo()->Context->Active, true), QQ::Equal(QQN::NarroContextInfo()->LanguageId, $intLanguageId)), QQ::OrderBy(QQN::NarroContextInfo()->Modified, 0));
     if ($objLastContextInfo) {
         $objProjectProgress->LastModified = $objLastContextInfo->Modified;
     }
     $objProjectProgress->Save();
     return true;
 }
 /**
  * Load a single NarroContextInfo object,
  * by ContextId, LanguageId Index(es)
  * @param integer $intContextId
  * @param integer $intLanguageId
  * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  * @return NarroContextInfo
  */
 public static function LoadByContextIdLanguageId($intContextId, $intLanguageId, $objOptionalClauses = null)
 {
     return NarroContextInfo::QuerySingle(QQ::AndCondition(QQ::Equal(QQN::NarroContextInfo()->ContextId, $intContextId), QQ::Equal(QQN::NarroContextInfo()->LanguageId, $intLanguageId)), $objOptionalClauses);
 }