示例#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());
         }
     }
 }
 /**
  * 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;
     }
 }
 public function __construct(NarroUser $objUser, $objParentObject, $strControlId = null)
 {
     // Call the Parent
     try {
         parent::__construct($objParentObject, $strControlId);
     } catch (QCallerException $objExc) {
         $objExc->IncrementOffset();
         throw $objExc;
     }
     $this->strTemplate = dirname(__FILE__) . '/' . __CLASS__ . '.tpl.php';
     $this->objUser = $objUser;
     $this->pnlTranslatedPerProjectPie = new QDatabasePieChart($this);
     $this->pnlTranslatedPerProjectPie->Query = sprintf('
                         SELECT
                             narro_project.project_name AS label, COUNT(narro_suggestion.suggestion_id) AS cnt
                         FROM
                             narro_suggestion, narro_context, narro_project
                         WHERE
                             narro_context.text_id = narro_suggestion.text_id AND
                             narro_project.project_id = narro_context.project_id AND
                             narro_suggestion.language_id=%d AND
                             narro_suggestion.user_id=%d
                         GROUP BY narro_context.project_id', QApplication::GetLanguageId(), $this->objUser->UserId);
     $intSuggestionCount = NarroSuggestion::CountByUserId($this->objUser->UserId);
     $this->pnlTranslatedPerProjectPie->Total = $intSuggestionCount;
     $this->pnlTranslatedPerProjectPie->MinimumDataValue = 0;
     $this->pnlApprovedPie = new QPieChart($this);
     $this->pnlApprovedPie->Total = $this->pnlTranslatedPerProjectPie->Total;
     $this->pnlApprovedPie->MinimumDataValue = 0;
     $objDatabase = NarroContextInfo::GetDatabase();
     $strQuery = sprintf("\n                            SELECT\n                                DISTINCT narro_context_info.valid_suggestion_id\n                            FROM\n                                narro_context_info, narro_suggestion\n                            WHERE\n                                narro_context_info.valid_suggestion_id=narro_suggestion.suggestion_id AND\n                                narro_suggestion.user_id=%d", $this->objUser->UserId);
     $objDbResult = $objDatabase->Query($strQuery);
     $intValidSuggestionCount = $objDbResult->CountRows();
     $this->pnlApprovedPie->Data = array(t('Approved') => $intValidSuggestionCount, t('Not approved') => $intSuggestionCount - $intValidSuggestionCount);
     $this->tabActivity = new QTabs($this);
     $this->dtgSuggestions_Create();
     $arrHeaders[] = t('Translations');
     $this->dtgReviews_Create();
     $arrHeaders[] = t('Reviews');
     $this->dtgComments_Create();
     $arrHeaders[] = t('Comments');
     $this->dtgVotes_Create();
     $arrHeaders[] = t('Votes');
     if (QApplication::HasPermissionForThisLang('Administrator') || QApplication::GetUserId() == $this->objUser->UserId) {
         $this->dtgLog_Create();
         $arrHeaders[] = t('Logged messages');
     }
     $this->tabActivity->Headers = $arrHeaders;
 }
 public function btnReset_Click($strFormId, $strControlId, $strParameter)
 {
     NarroContextInfo::GetDatabase()->Query(sprintf("DELETE FROM narro_context_info USING narro_context_info LEFT JOIN narro_context ON narro_context_info.context_id=narro_context.context_id WHERE narro_context_info.language_id=%d AND narro_context.project_id=%d", QApplication::GetLanguageId(), $this->objProject->ProjectId));
     $this->objProject->CountAllTextsByLanguage();
     $this->objProject->CountApprovedTextsByLanguage();
     $this->objProject->CountAllWordsByLanguage();
     $this->objProject->CountTranslatedTextsByLanguage();
     $this->lblMessage->Text = sprintf(t('The project was successfuly reset for %s. You need to import it again for this language to start over.'), QApplication::$TargetLanguage->LanguageName);
 }
 public function btnReplace_Click()
 {
     if (!QApplication::HasPermissionForThisLang('Can approve')) {
         return false;
     }
     if ($this->txtReplace->Display == false) {
         $this->txtReplace->Display = true;
     } else {
         if ($this->txtSearch->Text == '') {
             return false;
         }
         if ($this->txtReplace->Text == '') {
             return false;
         }
         $strQuery = NarroContextInfo::GetQueryForConditions($objQueryBuilder, QQ::AndCondition($this->arrConditions), $this->arrClauses);
         $objDbResult = NarroContextInfo::GetDatabase()->Query($strQuery);
         if ($objDbResult) {
             $intReplaceCnt = 0;
             $intApproved = 0;
             $intTranslations = 0;
             $arrProcessed = array();
             while ($objDbRow = $objDbResult->GetNextRow()) {
                 $objContextInfo = NarroContextInfo::InstantiateDbRow($objDbRow, null, null, null, $objQueryBuilder->ColumnAliasArray);
                 if (in_array($objContextInfo->ContextInfoId, $arrProcessed)) {
                     continue;
                 } else {
                     $arrProcessed[] = $objContextInfo->ContextInfoId;
                 }
                 $objReplaceSuggestion = null;
                 if (preg_match("/^'.*'\$/", $this->txtSearch->Text)) {
                     $strToReplace = substr($this->txtSearch->Text, 1, -1);
                 } else {
                     $strToReplace = $this->txtSearch->Text;
                 }
                 if ($strToReplace == $objContextInfo->Context->Text->TextValue) {
                     $objReplaceSuggestion = NarroSuggestion::LoadByTextIdLanguageIdSuggestionValueMd5($objContextInfo->Context->TextId, QApplication::GetLanguageId(), md5($this->txtReplace->Text));
                     if (!$objReplaceSuggestion) {
                         $objSuggestion = new NarroSuggestion();
                         $objSuggestion->UserId = QApplication::GetUserId();
                         $objSuggestion->TextId = $objContextInfo->Context->TextId;
                         $objSuggestion->LanguageId = QApplication::GetLanguageId();
                         $objSuggestion->SuggestionValue = $this->txtReplace->Text;
                         $objSuggestion->HasComments = 0;
                         $objSuggestion->IsImported = 0;
                         $objSuggestion->Created = QDateTime::Now();
                         $objSuggestion->Modified = null;
                         $objSuggestion->Save();
                         $intTranslations++;
                         $objReplaceSuggestion = $objSuggestion;
                     }
                 }
                 if ($objReplaceSuggestion instanceof NarroSuggestion) {
                     $intReplaceCnt++;
                     if ($objContextInfo->ValidSuggestionId != $objReplaceSuggestion->SuggestionId || $this->chkApprove->Checked) {
                         if ($objContextInfo->ValidSuggestionId == null) {
                             $intApproved++;
                         }
                         $objContextInfo->ValidSuggestionId = $objReplaceSuggestion->SuggestionId;
                         $objContextInfo->ValidatorUserId = QApplication::GetUserId();
                         $objContextInfo->Modified = QDateTime::Now();
                         $objContextInfo->Save();
                     }
                 }
             }
             $this->dtrText->RemoveChildControls(true);
             $this->btnReplace->Refresh();
             QApplication::ExecuteJavaScript(sprintf('jQuery(\'#%s\').after(\'&nbsp;<small style="padding: 2px;" class="ui-state-highlight ui-corner-all"><span style="width:16px; height: 16px; display:inline-block" class="ui-icon ui-icon-info"></span>&nbsp;%s.</small>\')', $this->btnReplace->ControlId, sprintf(t('%d occurences of "%s" translated with "%s", out of which %d were already approved, %d translations added.'), $intReplaceCnt, $strToReplace, $this->txtReplace->Text, $intApproved, $intTranslations)));
         }
     }
 }
 /**
  * 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 '';
     }
 }
示例#7
0
文件: rss.php 项目: Jobava/narro
 if (isset($objProject) && $objProject instanceof NarroProject) {
     $strCacheId = sprintf('rssfeed_context_info_changes_%d_%d', $objProject->ProjectId, QApplication::QueryString('l'));
 } else {
     $strCacheId = sprintf('rssfeed_context_info_changes_%d', QApplication::QueryString('l'));
 }
 if (!($objRssFeed = QApplication::$Cache->load($strCacheId))) {
     $objRssFeed = new QRssFeed(sprintf(t('Context changes in %s'), t(QApplication::$TargetLanguage->LanguageName)), __HTTP_URL__ . __VIRTUAL_DIRECTORY__ . __SUBDIRECTORY__, sprintf(t('Get the latest context information changes in %s'), t(QApplication::$TargetLanguage->LanguageName)));
     $objRssFeed->PubDate = new QDateTime(QDateTime::Now);
     $objRssFeed->Language = strtolower(str_replace('_', '-', QApplication::$TargetLanguage->LanguageCode));
     $strDescription = '';
     if (isset($objProject) && $objProject instanceof NarroProject) {
         $objCondition = QQ::AndCondition(QQ::Equal(QQN::NarroContextInfo()->LanguageId, QApplication::GetLanguageId()), QQ::Equal(QQN::NarroContextInfo()->Context->ProjectId, $objProject->ProjectId));
     } else {
         $objCondition = QQ::Equal(QQN::NarroContextInfo()->LanguageId, QApplication::GetLanguageId());
     }
     foreach (NarroContextInfo::QueryArray($objCondition, array(QQ::OrderBy(QQN::NarroContextInfo()->Modified, 0), QQ::LimitInfo(20, 0))) as $intKey => $objNarroContextInfo) {
         $strContextLink = sprintf(__HTTP_URL__ . __VIRTUAL_DIRECTORY__ . __SUBDIRECTORY__ . '/' . NarroLink::Translate($objNarroContextInfo->Context->ProjectId, '', 0, '', 0, 0, 10, 0, $objNarroContextInfo->ContextInfoId));
         $strProjectLink = sprintf(__HTTP_URL__ . __VIRTUAL_DIRECTORY__ . __SUBDIRECTORY__ . '/' . NarroLink::ProjectTextList($objNarroContextInfo->Context->ProjectId, NarroTranslatePanel::SHOW_ALL, ''));
         $strUserLink = __HTTP_URL__ . __VIRTUAL_DIRECTORY__ . __SUBDIRECTORY__ . '/' . NarroLink::UserProfile($objNarroContextInfo->ValidatorUserId);
         if (isset($objProject) && $objProject instanceof NarroProject) {
             $strItemName = '';
         } else {
             $strItemName = $objNarroContextInfo->Context->Project->ProjectName . ' :: ';
         }
         $objItem = new QRssItem($strItemName . (strlen($objNarroContextInfo->Context->Text->TextValue) > 124 ? substr($objNarroContextInfo->Context->Text->TextValue, 0, 124) . '...' : $objNarroContextInfo->Context->Text->TextValue), $strContextLink);
         $objItem->Description = sprintf('<p>' . t('Project') . ': <a href="%s">%s</a></p>', $strProjectLink, $objNarroContextInfo->Context->Project->ProjectName) . sprintf('<p>' . t('Context') . ': <a href="%s">%s</a></p>', $strContextLink, NarroString::HtmlEntities($objNarroContextInfo->Context->Context)) . sprintf('<p>' . t('Original text') . ': %s</p>', $objNarroContextInfo->Context->TextAccessKey ? NarroString::Replace($objNarroContextInfo->Context->TextAccessKey, '<u>' . $objNarroContextInfo->Context->TextAccessKey . '</u>', NarroString::HtmlEntities($objNarroContextInfo->Context->Text->TextValue), 1) : NarroString::HtmlEntities($objNarroContextInfo->Context->Text->TextValue)) . ($objNarroContextInfo->ValidSuggestionId ? sprintf('<p>' . t('Approved suggestion') . ': %s</p>', $objNarroContextInfo->Context->TextAccessKey ? NarroString::Replace($objNarroContextInfo->SuggestionAccessKey, '<u>' . $objNarroContextInfo->SuggestionAccessKey . '</u>', NarroString::HtmlEntities($objNarroContextInfo->ValidSuggestion->SuggestionValue), 1) : NarroString::HtmlEntities($objNarroContextInfo->ValidSuggestion->SuggestionValue)) : '') . ($objNarroContextInfo->HasSuggestions ? sprintf(t('The text has %s suggestions'), NarroSuggestion::QueryCount(QQ::AndCondition(QQ::Equal(QQN::NarroSuggestion()->TextId, $objNarroContextInfo->Context->TextId), QQ::Equal(QQN::NarroSuggestion()->LanguageId, QApplication::GetLanguageId())))) : t('The text has no suggestions')) . ($objNarroContextInfo->ValidSuggestionId && $objNarroContextInfo->ValidatorUserId != NarroUser::ANONYMOUS_USER_ID ? sprintf('<p>' . t('Approved by') . ': <a href="%s">%s</a>', $strUserLink, $objNarroContextInfo->ValidSuggestionId ? $objNarroContextInfo->ValidatorUser->RealName : '') : '');
         $objItem->PubDate = new QDateTime($objNarroContextInfo->Modified);
         $objItem->Author = $objNarroContextInfo->ValidSuggestionId ? $objNarroContextInfo->ValidatorUser->RealName : '';
         $objRssFeed->AddItem($objItem);
         $strDescription = '';
     }
示例#8
0
 public static function CountByFileName($strFileName, $intFilter, $objExtraCondition = null)
 {
     if (!is_object($objExtraCondition)) {
         $objExtraCondition = QQ::All();
     }
     if (trim($strFileName) == '') {
         $objSearchCondition = QQ::All();
     } elseif (preg_match("/^'.*'\$/", $strFileName)) {
         $objSearchCondition = QQ::Equal(QQN::NarroContextInfo()->Context->File->FileName, substr($strFileName, 1, -1));
     } else {
         $objSearchCondition = QQ::Like(QQN::NarroContextInfo()->Context->File->FileName, '%' . $strFileName . '%');
     }
     switch ($intFilter) {
         case NarroTextListForm::SHOW_UNTRANSLATED_TEXTS:
             $objFilterCondition = QQ::Equal(QQN::NarroContextInfo()->HasSuggestions, 0);
             break;
         case NarroTextListForm::SHOW_APPROVED_TEXTS:
             $objFilterCondition = QQ::IsNotNull(QQN::NarroContextInfo()->ValidSuggestionId);
             break;
         case NarroTextListForm::SHOW_TEXTS_THAT_REQUIRE_APPROVAL:
             $objFilterCondition = QQ::AndCondition(QQ::IsNull(QQN::NarroContextInfo()->ValidSuggestionId), QQ::Equal(QQN::NarroContextInfo()->HasSuggestions, 1));
             break;
         default:
             // no filters
             $objFilterCondition = QQ::All();
     }
     $intContextCount = NarroContextInfo::QueryCount(QQ::AndCondition($objSearchCondition, $objFilterCondition, $objExtraCondition), array(QQ::GroupBy(QQN::NarroContextInfo()->ContextId)));
     return $intContextCount;
 }
示例#9
0
 /**
  * Counts all associated NarroContextInfosAsContext
  * @return int
  */
 public function CountNarroContextInfosAsContext()
 {
     if (is_null($this->intContextId)) {
         return 0;
     }
     return NarroContextInfo::CountByContextId($this->intContextId);
 }
示例#10
0
 public function ExportFile($strTemplateFile, $strTranslatedFile)
 {
     $arrSourceKey = $this->FileAsArray($strTemplateFile);
     $intElapsedTime = time() - $intTime;
     if ($intElapsedTime > 0) {
         // NarroLogger::LogDebug(sprintf('Preprocessing %s took %d seconds.', $this->objFile->FileName, $intElapsedTime));
     }
     // NarroLogger::LogDebug(sprintf('Found %d contexts in file %s.', count($arrSourceKey), $this->objFile->FileName));
     if (is_array($arrSourceKey)) {
         $arrTranslationObjects = 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->Active, 1)));
         foreach ($arrTranslationObjects as $objNarroContextInfo) {
             $strTranslation = $this->GetExportedSuggestion($objNarroContextInfo);
             if (isset($arrSourceKey[$objNarroContextInfo->Context->Context])) {
                 $arrSourceKey[$objNarroContextInfo->Context->Context]->Value = $strTranslation;
             } else {
                 if ($this->blnSkipUntranslated == false) {
                     $arrSourceKey[$objNarroContextInfo->Context->Context]->Value = $objNarroContextInfo->Context->Text->TextValue;
                 } else {
                     unset($arrTranslation[$objNarroContextInfo->Context->Context]);
                 }
             }
         }
         $hndTranslationFile = fopen($strTranslatedFile, 'w');
         foreach ($arrSourceKey as $strContext => $objEntity) {
             /* @var $objEntity NarroFileEntity */
             fwrite($hndTranslationFile, $objEntity->Key . "\n");
             fwrite($hndTranslationFile, $objEntity->Comment . "\n");
             fwrite($hndTranslationFile, $objEntity->Value . "\n\n");
         }
         fclose($hndTranslationFile);
         NarroUtils::Chmod($strTranslatedFile, 0666);
         return true;
     } else {
         NarroLogger::LogWarn(sprintf('Found a empty template (%s), copying the original', $strTemplateFile));
         copy($strTemplateFile, $strTranslatedFile);
         NarroUtils::Chmod($strTranslatedFile, 0666);
         return false;
     }
 }
 /**
  * This function does the opposite of GetAccessKeys
  * @param array $arrTemplate an array with context as keys and original texts as values
  * @return array $arrTranslation an array with context as keys and translations as values
  */
 public function GetTranslations($arrTemplate)
 {
     $arrTranslation = array();
     $arrTranslationObjects = 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->Active, 1)), QQ::Expand(QQN::NarroContextInfo()->Context));
     foreach ($arrTranslationObjects as $objNarroContextInfo) {
         $arrTranslation[$objNarroContextInfo->Context->Context] = $this->GetExportedSuggestion($objNarroContextInfo);
         if ($arrTranslation[$objNarroContextInfo->Context->Context] === false) {
             if ($this->blnSkipUntranslated == false) {
                 $arrTranslation[$objNarroContextInfo->Context->Context] = $objNarroContextInfo->Context->Text->TextValue;
             } else {
                 unset($arrTranslation[$objNarroContextInfo->Context->Context]);
             }
         }
         if ($objNarroContextInfo->Context->TextAccessKey) {
             if ($objNarroContextInfo->SuggestionAccessKey && isset($arrTemplate[$objNarroContextInfo->Context->Context]->AccessKeyCtx)) {
                 $arrTranslation[$arrTemplate[$objNarroContextInfo->Context->Context]->AccessKeyCtx] = $objNarroContextInfo->SuggestionAccessKey;
             } elseif (isset($arrTemplate[$objNarroContextInfo->Context->Context]->AccessKeyCtx)) {
                 $arrTranslation[$arrTemplate[$objNarroContextInfo->Context->Context]->AccessKeyCtx] = $objNarroContextInfo->Context->TextAccessKey;
             } else {
                 // is there a access key set in the translation ?
                 if ($objNarroContextInfo->SuggestionAccessKey && strstr($arrTranslation[$objNarroContextInfo->Context->Context], $objNarroContextInfo->SuggestionAccessKey)) {
                     $arrTranslation[$objNarroContextInfo->Context->Context] = $this->ApplySuitableAccessKey($arrTranslation[$objNarroContextInfo->Context->Context], $objNarroContextInfo->SuggestionAccessKey);
                 } elseif ($strTextWithAccKey = $this->ApplySuitableAccessKey($arrTranslation[$objNarroContextInfo->Context->Context])) {
                     $arrTranslation[$objNarroContextInfo->Context->Context] = $strTextWithAccKey;
                 }
             }
         }
         if ($objNarroContextInfo->Context->TextCommandKey) {
             if ($objNarroContextInfo->SuggestionCommandKey && isset($arrTemplate[$objNarroContextInfo->Context->Context]->CommandKeyCtx)) {
                 $arrTranslation[$arrTemplate[$objNarroContextInfo->Context->Context]->CommandKeyCtx] = $objNarroContextInfo->SuggestionCommandKey;
             } else {
                 $arrTranslation[$arrTemplate[$objNarroContextInfo->Context->Context]->CommandKeyCtx] = $objNarroContextInfo->Context->TextCommandKey;
             }
         }
     }
     return $arrTranslation;
 }
示例#12
0
 /**
  * Counts all associated NarroContextInfosAsValidatorUser
  * @return int
  */
 public function CountNarroContextInfosAsValidatorUser()
 {
     if (is_null($this->intUserId)) {
         return 0;
     }
     return NarroContextInfo::CountByValidatorUserId($this->intUserId);
 }
 /**
  * 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;
     }
 }
 /**
  * This Form_Validate event handler allows you to specify any custom Form Validation rules.
  * It will also Blink() on all invalid controls, as well as Focus() on the top-most invalid control.
  */
 protected function Form_Validate()
 {
     // By default, we report the result of validation from the parent
     $blnToReturn = parent::Form_Validate();
     // Custom Validation Rules
     // TODO: Be sure to set $blnToReturn to false if any custom validation fails!
     // Check for records that may violate Unique Clauses
     if (($objNarroContextInfo = NarroContextInfo::LoadByContextIdLanguageId($this->lstContext->SelectedValue, $this->lstLanguage->SelectedValue)) && $objNarroContextInfo->ContextInfoId != $this->mctNarroContextInfo->NarroContextInfo->ContextInfoId) {
         $blnToReturn = false;
         $this->lstContext->Warning = QApplication::Translate("Already in Use");
         $this->lstLanguage->Warning = QApplication::Translate("Already in Use");
     }
     $blnFocused = false;
     foreach ($this->GetErrorControls() as $objControl) {
         // Set Focus to the top-most invalid control
         if (!$blnFocused) {
             $objControl->Focus();
             $blnFocused = true;
         }
         // Blink on ALL invalid controls
         $objControl->Blink();
     }
     return $blnToReturn;
 }
 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);
     }
 }
 public function ExportFile($strTemplateFile, $strTranslatedFile)
 {
     $strTemplateContents = file_get_contents($strTemplateFile);
     if (!$strTemplateContents) {
         NarroLogger::LogWarn(sprintf('Found a empty template (%s), copying the original', $strTemplateFile));
         copy($strTemplateFile, $strTranslatedFile);
         chmod($strTranslatedFile, 0666);
         return false;
     }
     if (strstr($strTemplateContents, '#define MOZ_LANGPACK_CONTRIBUTORS')) {
         $strTemplateContents = preg_replace('/^#\\s+#define MOZ_LANGPACK_CONTRIBUTORS.*$/m', '#define MOZ_LANGPACK_CONTRIBUTORS <em:contributor>Joe Solon</em:contributor> <em:contributor>Suzy Solon</em:contributor>', $strTemplateContents);
     }
     $arrTemplateContents = explode("\n", $strTemplateContents);
     $strComment = '';
     foreach ($arrTemplateContents as $intPos => $strLine) {
         if (preg_match('/^#define\\s+([^\\s]+)\\s+(.+)$/s', trim($strLine), $arrMatches)) {
             $arrTemplate[trim($arrMatches[1])] = trim($arrMatches[2]);
             $arrTemplateLines[trim($arrMatches[1])] = $arrMatches[0];
             $arrTemplateComment[trim($arrMatches[1])] = $strComment;
             $strComment = '';
         } elseif (trim($strLine) != '' && $strLine[0] != '#') {
             // NarroLogger::LogDebug(sprintf('Skipped line "%s" from the template "%s".', $strLine, $this->objFile->FileName));
         } elseif ($strLine[0] == '#') {
             $strComment .= "\n" . $strLine;
         }
     }
     $strTranslateContents = '';
     if (count($arrTemplate) < 1) {
         return false;
     }
     $arrTranslationObjects = 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->Active, 1)));
     foreach ($arrTranslationObjects as $objNarroContextInfo) {
         if ($objNarroContextInfo->ValidSuggestionId > 0) {
             $arrTranslation[$objNarroContextInfo->Context->Context] = $this->GetExportedSuggestion($objNarroContextInfo);
             if ($arrTranslation[$objNarroContextInfo->Context->Context] === false) {
                 $arrTranslation[$objNarroContextInfo->Context->Context] = $objNarroContextInfo->Context->Text->TextValue;
             }
             if ($objNarroContextInfo->Context->TextAccessKey) {
                 if ($objNarroContextInfo->SuggestionAccessKey) {
                     $strAccessKey = $objNarroContextInfo->SuggestionAccessKey;
                 } else {
                     $strAccessKey = $objNarroContextInfo->Context->TextAccessKey;
                 }
                 $arrTranslation[$objNarroContextInfo->Context->Context] = preg_replace('/' . $strAccessKey . '/', '&' . $strAccessKey, $arrTranslation[$objNarroContextInfo->Context->Context], 1);
                 NarroImportStatistics::$arrStatistics['Texts that have access keys']++;
             } else {
                 NarroImportStatistics::$arrStatistics["Texts that don't have access keys"]++;
             }
         } else {
             // NarroLogger::LogDebug(sprintf('In file "%s", the context "%s" does not have a valid suggestion.', $this->objFile->FileName, $objNarroContextInfo->Context->Context));
             NarroImportStatistics::$arrStatistics['Texts without valid suggestions']++;
             NarroImportStatistics::$arrStatistics['Texts kept as original']++;
         }
     }
     $strTranslateContents = $strTemplateContents;
     foreach ($arrTemplate as $strKey => $strOriginalText) {
         if (isset($arrTranslation[$strKey])) {
             $arrResult = QApplication::$PluginHandler->ExportSuggestion($strOriginalText, $arrTranslation[$strKey], $strKey, $this->objFile, $this->objProject);
             if ($arrResult[1] != '' && $arrResult[0] == $strOriginalText && $arrResult[2] == $strKey && $arrResult[3] == $this->objFile && $arrResult[4] == $this->objProject) {
                 $arrTranslation[$strKey] = $arrResult[1];
             } else {
                 NarroLogger::LogWarn(sprintf('The plugin "%s" returned an unexpected result while processing the suggestion "%s": %s', QApplication::$PluginHandler->CurrentPluginName, $arrTranslation[$strKey], var_export($arrResult, true)));
             }
             if (strstr($strTranslateContents, sprintf('#define %s %s', $strKey, $strOriginalText))) {
                 $strTranslateContents = str_replace(sprintf('#define %s %s', $strKey, $strOriginalText), sprintf('#define %s %s', $strKey, $arrTranslation[$strKey]), $strTranslateContents);
             } else {
                 NarroLogger::LogWarn(sprintf('Can\'t find "%s" in the file "%s"'), $strKey . $strGlue . $strOriginalText, $this->objFile->FileName);
             }
             if (strstr($arrTranslation[$strKey], "\n")) {
                 NarroLogger::LogWarn(sprintf('Skpping translation "%s" because it has a newline in it'), $arrTranslation[$strKey]);
                 continue;
             }
         } else {
             // NarroLogger::LogDebug(sprintf('Couldn\'t find the key "%s" in the translations, using the original text.', $strKey, $this->objFile->FileName));
             NarroImportStatistics::$arrStatistics['Texts kept as original']++;
             if ($this->blnSkipUntranslated == true) {
             }
             if ($this->blnSkipUntranslated == true) {
                 if (isset($arrTemplateComment[$strKey]) && $arrTemplateComment[$strKey] != '') {
                     $strTranslateContents = str_replace($arrTemplateComment[$strKey] . "\n", "\n", $strTranslateContents);
                     $strTranslateContents = str_replace(sprintf("#define %s %s\n", $strKey, $strOriginalText), '', $strTranslateContents);
                 }
             }
         }
     }
     if (file_exists($strTranslatedFile) && !is_writable($strTranslatedFile) && !unlink($strTranslatedFile)) {
         NarroLogger::LogError(sprintf('Can\'t delete the file "%s"', $strTranslatedFile));
     }
     if (!file_put_contents($strTranslatedFile, $strTranslateContents)) {
         NarroLogger::LogError(sprintf('Can\'t write to file "%s"', $strTranslatedFile));
     }
     @chmod($strTranslatedFile, 0666);
 }
示例#17
0
 /**
  * Counts all associated NarroContextInfosAsLanguage
  * @return int
  */
 public function CountNarroContextInfosAsLanguage()
 {
     if (is_null($this->intLanguageId)) {
         return 0;
     }
     return NarroContextInfo::CountByLanguageId($this->intLanguageId);
 }
示例#18
0
 /**
  * A translation here consists of the project, file, text, translation, context, 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 $strComment a comment from the imported file
  * @param string $strOriginalCmdKey command key for the original text
  * @param string $strTranslationCmdKey command key for the translated text
  */
 protected function AddTranslation($strOriginal, $strOriginalAccKey = null, $strTranslation, $strTranslationAccKey = null, $strContext = '', $strComment = null, $strOriginalCmdKey = null, $strTranslationCmdKey = null)
 {
     if ($strOriginal == '') {
         return false;
     }
     $blnContextInfoChanged = false;
     $blnContextChanged = false;
     $objText = $this->GetText($strOriginal);
     if (!$objText instanceof NarroText) {
         $objText = NarroText::LoadByTextValueMd5(md5($strOriginal));
     }
     if (!$this->blnOnlySuggestions && !$objText instanceof NarroText) {
         $objText = new NarroText();
         $objText->TextValue = $strOriginal;
         try {
             $objText->Save();
             // NarroLogger::LogDebug(sprintf('Added text "%s" from the file "%s"', $strOriginal, $this->objFile->FileName));
             NarroImportStatistics::$arrStatistics['Imported texts']++;
         } catch (Exception $objExc) {
             NarroLogger::LogError(sprintf('Error while adding "%s": %s', $strOriginal, $objExc->getMessage()));
             NarroImportStatistics::$arrStatistics['Skipped contexts']++;
             NarroImportStatistics::$arrStatistics['Skipped suggestions']++;
             NarroImportStatistics::$arrStatistics['Skipped texts']++;
             NarroImportStatistics::$arrStatistics['Texts that had errors while adding']++;
             /**
              * If there's no text, there's no context and no suggestion
              */
             return false;
         }
     } elseif (!$objText instanceof NarroText) {
         // NarroLogger::LogDebug('No text found');
         /**
          * If there's no text, there's no context and no suggestion
          */
         return false;
     }
     $objContext = $this->GetContext($strOriginal, $strContext, $strComment);
     if (!$objContext) {
         // NarroLogger::LogDebug('No context found, trying database');
         $objContext = NarroContext::LoadByTextIdContextMd5FileIdCommentMd5($objText->TextId, md5($strContext), $this->objFile->FileId, md5($strComment));
     }
     if (!$this->blnOnlySuggestions && !$objContext instanceof NarroContext) {
         // NarroLogger::LogDebug('Still no context, creating one');
         $objContext = new NarroContext();
         $objContext->TextId = $objText->TextId;
         $objContext->ProjectId = $this->objProject->ProjectId;
         $objContext->Context = $strContext;
         $objContext->ContextMd5 = md5($strContext);
         $objContext->FileId = $this->objFile->FileId;
         $objContext->Active = 1;
         $objContext->Modified = QDateTime::Now();
         $objContext->Created = QDateTime::Now();
         $objContext->Comment = $strComment;
         $objContext->CommentMd5 = md5($strComment);
         try {
             $objContext->Save();
         } catch (Exception $objException) {
             NarroLogger::LogError(sprintf('An error occurred while saving the context: %s. Skipping the text "%s"', $objException->getMessage(), $strOriginal));
             return false;
         }
         // NarroLogger::LogDebug(sprintf('Added the context "%s" from the file "%s"', nl2br($strContext), $this->objFile->FileName));
         NarroImportStatistics::$arrStatistics['Imported contexts']++;
         $this->arrContextId[$objContext->ContextId] = $objContext->ContextId;
     } elseif ($objContext instanceof NarroContext) {
         // NarroLogger::LogDebug('Found context');
         $this->arrContextId[$objContext->ContextId] = $objContext->ContextId;
         NarroImportStatistics::$arrStatistics['Reused contexts']++;
     } else {
         // NarroLogger::LogDebug(sprintf('Cannot add the context for text "%s" from the file "%s" because the importer is running with the option to import only suggestions.', $objText->TextValue, $this->objFile->FilePath));
         return false;
     }
     /**
      * load the context info
      */
     $objContextInfo = $this->GetContextInfo($strOriginal, $strContext, $strComment);
     if (!$objContextInfo) {
         // NarroLogger::LogDebug('No context info found, trying database');
         $objContextInfo = NarroContextInfo::LoadByContextIdLanguageId($objContext->ContextId, $this->objTargetLanguage->LanguageId);
     }
     /**
      * Add context infos even if only suggestion is selected to allow users that have permissions only on one language to approve suggestions
      */
     if (!$objContextInfo instanceof NarroContextInfo) {
         // NarroLogger::LogDebug('Still no context info, creating one');
         $objContextInfo = new NarroContextInfo();
         $objContextInfo->ContextId = $objContext->ContextId;
         $objContextInfo->LanguageId = $this->objTargetLanguage->LanguageId;
         $objContextInfo->HasSuggestions = 0;
         $objContextInfo->Created = QDateTime::Now();
         $blnContextInfoChanged = true;
     } elseif ($objContextInfo instanceof NarroContextInfo) {
         // NarroLogger::LogDebug('Found context info');
         NarroImportStatistics::$arrStatistics['Reused context informations']++;
     }
     if ($objContext instanceof NarroContext && $objContextInfo instanceof NarroContextInfo) {
         /**
          * this lies outside the if/else if reusing contexts is activated, so if a context was moved in another file, we'll just update the file_id
          */
         if ($objContext->FileId != $this->objFile->FileId) {
             // NarroLogger::LogDebug('Context changed file');
             $blnContextChanged = true;
             $objContext->FileId = $this->objFile->FileId;
         }
         if ($objContext->Active == false) {
             // NarroLogger::LogDebug('Context is inactive');
             $blnContextChanged = true;
             $objContext->Active = true;
         }
         if ($objContext->TextAccessKey != $strOriginalAccKey) {
             // NarroLogger::LogDebug('Text access key changed for this context');
             $blnContextChanged = true;
             $objContext->TextAccessKey = $strOriginalAccKey;
         }
         if ($objContext->TextCommandKey != $strOriginalCmdKey) {
             // NarroLogger::LogDebug('Text command key changed for this context');
             $blnContextChanged = true;
             $objContext->TextCommandKey = $strOriginalCmdKey;
         }
     }
     if ($strTranslation == '') {
         // NarroLogger::LogDebug('No translation');
         /**
          * just ignore, used for import without suggestions
          */
         NarroImportStatistics::$arrStatistics['Texts without suggestions']++;
     } elseif ($this->blnCheckEqual && $strOriginal == $strTranslation) {
         // NarroLogger::LogDebug(sprintf('Skipped "%s" because "%s" has the same value. From "%s".', $strOriginal, $strTranslation, $this->objFile->FileName));
         NarroImportStatistics::$arrStatistics['Skipped suggestions']++;
         NarroImportStatistics::$arrStatistics['Suggestions that kept the original text']++;
     } elseif ($this->blnImportSuggestions) {
         /**
          * See if a suggestion already exists, fetch it
          */
         $objSuggestion = $this->GetSuggestion($strOriginal, $strTranslation);
         if (!$objSuggestion) {
             // NarroLogger::LogDebug('No translation, querying the database');
             $objSuggestion = NarroSuggestion::LoadByTextIdLanguageIdSuggestionValueMd5($objText->TextId, $this->objTargetLanguage->LanguageId, md5($strTranslation));
         }
         if (!$objSuggestion instanceof NarroSuggestion) {
             // NarroLogger::LogDebug('Still no translation, creating one');
             $objSuggestion = new NarroSuggestion();
             $objSuggestion->IsImported = 1;
             $objSuggestion->UserId = $this->objUser->UserId;
             $objSuggestion->TextId = $objText->TextId;
             $objSuggestion->LanguageId = $this->objTargetLanguage->LanguageId;
             $objSuggestion->SuggestionValue = $strTranslation;
             try {
                 $objSuggestion->Save();
             } catch (Exception $objException) {
                 NarroLogger::LogError(sprintf('An error occurred while adding the suggestion "%s": %s. Skipping the text "%s"', $strTranslation, $objException->getMessage(), $strOriginal));
                 return false;
             }
             /**
              * update the HasSuggestions if it was 0 and we added a suggestion
              */
             if ($objContextInfo instanceof NarroContextInfo && $objContextInfo->HasSuggestions == 0 && $objSuggestion instanceof NarroSuggestion) {
                 $objContextInfo->HasSuggestions = 1;
                 $blnContextInfoChanged = true;
             }
             NarroImportStatistics::$arrStatistics['Imported suggestions']++;
         } else {
             // NarroLogger::LogDebug('Found translation in the database');
             NarroImportStatistics::$arrStatistics['Reused suggestions']++;
         }
         if ($objContextInfo instanceof NarroContextInfo && $this->blnApprove && (is_null($objContextInfo->ValidSuggestionId) || $this->blnApproveAlreadyApproved) && $objContextInfo->ValidSuggestionId != $objSuggestion->SuggestionId) {
             // NarroLogger::LogDebug('Approving translation');
             $objContextInfo->ValidSuggestionId = $objSuggestion->SuggestionId;
             $objContextInfo->ValidatorUserId = QApplication::GetUserId();
             $blnContextInfoChanged = true;
             NarroImportStatistics::$arrStatistics['Approved suggestions']++;
         }
         if ($objContextInfo instanceof NarroContextInfo && !is_null($strTranslationAccKey) && $objContextInfo->SuggestionAccessKey != $strTranslationAccKey) {
             // NarroLogger::LogDebug('Translation access key changed');
             $blnContextInfoChanged = true;
             $objContextInfo->SuggestionAccessKey = $strTranslationAccKey;
         }
         if ($objContextInfo instanceof NarroContextInfo && !is_null($strTranslationCmdKey) && $objContextInfo->SuggestionCommandKey != $strTranslationCmdKey) {
             // NarroLogger::LogDebug('Translation command key changed');
             $blnContextInfoChanged = true;
             $objContextInfo->SuggestionCommandKey = $strTranslationCmdKey;
         }
     }
     if ($blnContextInfoChanged && $objContextInfo instanceof NarroContextInfo) {
         // NarroLogger::LogDebug('Context info modified, saving...');
         $objContextInfo->Modified = QDateTime::Now();
         try {
             $objContextInfo->Save();
         } catch (Exception $objExc) {
             NarroLogger::LogError(sprintf('Error while saving context info for context %s: %s', $strContext, $objExc->getMessage()));
             NarroImportStatistics::$arrStatistics['Skipped context infos']++;
         }
     }
     if ($blnContextChanged && $objContext instanceof NarroContext) {
         // NarroLogger::LogDebug('Context modified, saving...');
         $objContext->Modified = QDateTime::Now();
         try {
             $objContext->Save();
         } catch (Exception $objExc) {
             NarroLogger::LogError(sprintf('Error while saving context %s: %s', $strContext, $objExc->getMessage()));
             NarroImportStatistics::$arrStatistics['Skipped contexts']++;
         }
     }
     return true;
 }
示例#19
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;
 }
示例#20
0
 /**
  * Counts all associated NarroContextInfosAsValidSuggestion
  * @return int
  */
 public function CountNarroContextInfosAsValidSuggestion()
 {
     if (is_null($this->intSuggestionId)) {
         return 0;
     }
     return NarroContextInfo::CountByValidSuggestionId($this->intSuggestionId);
 }
 /**
  * Static Helper Method to Create using PK arguments
  * You must pass in the PK arguments on an object to load, or leave it blank to create a new one.
  * If you want to load via QueryString or PathInfo, use the CreateFromQueryString or CreateFromPathInfo
  * static helper methods.  Finally, specify a CreateType to define whether or not we are only allowed to
  * edit, or if we are also allowed to create a new one, etc.
  *
  * @param mixed $objParentObject QForm or QPanel which will be using this NarroContextInfoMetaControl
  * @param integer $intContextInfoId primary key value
  * @param QMetaControlCreateType $intCreateType rules governing NarroContextInfo object creation - defaults to CreateOrEdit
  * @return NarroContextInfoMetaControl
  */
 public static function Create($objParentObject, $intContextInfoId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit)
 {
     // Attempt to Load from PK Arguments
     if (strlen($intContextInfoId)) {
         $objNarroContextInfo = NarroContextInfo::Load($intContextInfoId);
         // NarroContextInfo was found -- return it!
         if ($objNarroContextInfo) {
             return new NarroContextInfoMetaControl($objParentObject, $objNarroContextInfo);
         } else {
             if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound) {
                 throw new QCallerException('Could not find a NarroContextInfo object with PK arguments: ' . $intContextInfoId);
             }
         }
         // If EditOnly is specified, throw an exception
     } else {
         if ($intCreateType == QMetaControlCreateType::EditOnly) {
             throw new QCallerException('No PK arguments specified');
         }
     }
     // If we are here, then we need to create a new record
     return new NarroContextInfoMetaControl($objParentObject, new NarroContextInfo());
 }
         error_log(sprintf('Found duplicates for "%s": %d', $objSuggestion->SuggestionValue, count($arrDuplicateSuggestions)));
         foreach ($arrDuplicateSuggestions as $objDuplicateSuggestion) {
             if ($objSuggestion->SuggestionValue !== $objDuplicateSuggestion->SuggestionValue) {
                 continue;
             }
             foreach (NarroSuggestionComment::LoadArrayBySuggestionId($objDuplicateSuggestion->SuggestionId) as $objSuggestionComment) {
                 error_log('Moving suggestion comment');
                 $objSuggestionComment->SuggestionId = $objSuggestion->SuggestionId;
                 $objSuggestionComment->Save();
             }
             foreach (NarroSuggestionVote::LoadArrayBySuggestionId($objDuplicateSuggestion->SuggestionId) as $objSuggestionVote) {
                 error_log('Moving suggestion vote');
                 $objSuggestionVote->SuggestionId = $objSuggestion->SuggestionId;
                 $objSuggestionVote->Save();
             }
             foreach (NarroContextInfo::LoadArrayByValidSuggestionId($objDuplicateSuggestion->SuggestionId) as $objApprovedSuggestion) {
                 error_log('Moving approved suggestion');
                 $objApprovedSuggestion->ValidSuggestionId = $objSuggestion->SuggestionId;
                 $objApprovedSuggestion->Save();
             }
             error_log(sprintf('Deleting suggestion %d %d "%s"', $objDuplicateSuggestion->SuggestionId, $objDuplicateSuggestion->LanguageId, $objDuplicateSuggestion->SuggestionValue));
             $objDuplicateSuggestion->Delete();
             $intDuplicateSuggestionsDeleted++;
         }
     }
     $objSuggestion->TextId = $objText->TextId;
     $objSuggestion->Save();
 }
 foreach (NarroContext::LoadArrayByTextId($objDuplicateText->TextId) as $objContext) {
     error_log('Moving text from context');
     $objContext->TextId = $objText->TextId;
 /**
  * Default / simple DataBinder for this Meta DataGrid.  This can easily be overridden
  * by calling SetDataBinder() on this DataGrid with another DataBinder of your choice.
  *
  * If a paginator is set on this DataBinder, it will use it.  If not, then no pagination will be used.
  * It will also perform any sorting (if applicable).
  */
 public function MetaDataBinder()
 {
     $objConditions = $this->Conditions;
     if (null !== $this->conAdditionalConditions) {
         $objConditions = QQ::AndCondition($this->conAdditionalConditions, $objConditions);
     }
     // Setup the $objClauses Array
     $objClauses = array();
     if (null !== $this->clsAdditionalClauses) {
         $objClauses = $this->clsAdditionalClauses;
     }
     // Remember!  We need to first set the TotalItemCount, which will affect the calcuation of LimitClause below
     if ($this->Paginator) {
         $this->TotalItemCount = NarroContextInfo::QueryCount($objConditions);
     }
     // If a column is selected to be sorted, and if that column has a OrderByClause set on it, then let's add
     // the OrderByClause to the $objClauses array
     if ($objClause = $this->OrderByClause) {
         array_push($objClauses, $objClause);
     }
     // Add the LimitClause information, as well
     if ($objClause = $this->LimitClause) {
         array_push($objClauses, $objClause);
     }
     // Set the DataSource to be a Query result from NarroContextInfo, given the clauses above
     $this->DataSource = NarroContextInfo::QueryArray($objConditions, $objClauses);
 }
 public function btnDelete_Click($strFormId, $strControlId, $strParameter)
 {
     $objSuggestion = NarroSuggestion::Load($strParameter);
     if ($this->btnSaveIgnore && $this->btnSaveIgnore->ControlId == $strControlId || !$this->IsSuggestionUsed($objSuggestion)) {
         QApplication::$PluginHandler->DeleteSuggestion($this->objContextInfo->Context->Text->TextValue, $objSuggestion->SuggestionValue, $this->objContextInfo->Context->Context, $this->objContextInfo->Context->File, $this->objContextInfo->Context->Project);
         if (!QApplication::HasPermissionForThisLang('Can delete any suggestion', $this->objContextInfo->Context->ProjectId) && ($objSuggestion->UserId != QApplication::GetUserId() || QApplication::GetUserId() == NarroUser::ANONYMOUS_USER_ID)) {
             return false;
         }
         $objSuggestion->Delete();
         if (NarroSuggestion::CountByTextIdLanguageId($this->objContextInfo->Context->TextId, QApplication::GetLanguageId()) == 0) {
             $arrCtx = NarroContextInfo::QueryArray(QQ::AndCondition(QQ::Equal(QQN::NarroContextInfo()->Context->TextId, $this->objContextInfo->Context->TextId), QQ::Equal(QQN::NarroContextInfo()->LanguageId, QApplication::GetLanguageId())));
             foreach ($arrCtx as $objContextInfo) {
                 $objContextInfo->HasSuggestions = 0;
                 $objContextInfo->Modified = QDateTime::Now();
                 $objContextInfo->Save();
             }
             $this->objContextInfo->HasSuggestions = 0;
             $this->objContextInfo->Save();
         }
         foreach ($this->Form->GetAllControls() as $ctl) {
             if ($ctl instanceof NarroContextInfoEditor) {
                 if ($ctl->TranslationList && $ctl->Text->Text == $this->lblText->Text) {
                     $ctl->btnHelp_Click($this->Form->FormId, $ctl->btnHelp->ControlId, '');
                 }
             }
         }
         $this->lblMessage->Text = t('Suggestion succesfully deleted.');
         $this->blnModified = true;
         if ($this->btnSaveIgnore) {
             $this->btnSave->Display = true;
         }
     } else {
         $this->btnSaveIgnore_Create();
         $this->btnSaveIgnore->Display = true;
         $this->btnSaveIgnore->Text = t('Ignore and delete');
         $this->btnSaveIgnore->RemoveAllActions('click');
         $this->btnSaveIgnore->ActionParameter = $strParameter;
         $this->btnSaveIgnore->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnDelete_Click'));
     }
 }
示例#25
0
 public static function GetSoapArrayFromArray($objArray)
 {
     if (!$objArray) {
         return null;
     }
     $objArrayToReturn = array();
     foreach ($objArray as $objObject) {
         array_push($objArrayToReturn, NarroContextInfo::GetSoapObjectFromObject($objObject, true));
     }
     return unserialize(serialize($objArrayToReturn));
 }