private function checkStrings($sCheckLanguageId = null) { $aAllStrings = array(); foreach (TranslationQuery::create()->orderByStringKey()->find() as $oString) { if (!in_array($oString->getStringKey(), $aAllStrings)) { $aAllStrings[] = $oString->getStringKey(); } } $aAllLanguages = array(); foreach (LanguageQuery::create()->orderById()->find() as $oLanguage) { $aAllLanguages[$oLanguage->getId()] = $oLanguage->getLanguageName(); } foreach ($aAllStrings as $sStringKey) { foreach ($aAllLanguages as $sLanguageId => $sLanguageName) { if ($sCheckLanguageId && $sCheckLanguageId === $sLanguageId) { continue; } $oString = TranslationPeer::getString($sStringKey, $sLanguageId, self::$EMPTY_STRING_KEY); if ($oString === self::$EMPTY_STRING_KEY) { $sText = TranslationPeer::getString('wns.check.check_string_message', null, null, array('string_key' => $sStringKey, 'language_id' => $sLanguageId)); $this->log($sText, $sLanguageId, self::LOG_LEVEL_WARNING); } } } return $this->aLogMessages; }
public function saveData($aTagData) { $aTagData['name'] = StringUtil::normalize($aTagData['name']); if ($this->iTagId === null) { $oTag = new Tag(); } else { $oTag = TagQuery::create()->findPk($this->iTagId); } $this->validate($aTagData); if (!Flash::noErrors()) { throw new ValidationException(); } $sStringName = "tag.{$aTagData['name']}"; if ($oTag->getName() !== $aTagData['name']) { //Rename Strings for the tag $sOldStringName = "tag.{$oTag->getName()}"; foreach (TranslationQuery::create()->filterByStringKey($sOldStringName)->find() as $oString) { $sLanguageId = $oString->getLanguageId(); //You can’t technically rename strings because string_key is the PKEY so we delete it and re-generate $oString->delete(); $oString = new Translation(); $oString->setStringKey($sStringName); $oString->setLanguageId($sLanguageId); $oString->save(); } $oTag->setName($aTagData['name']); } foreach ($aTagData['edited_languages'] as $iIndex => $sLanguageId) { TranslationPeer::addOrUpdateString($sStringName, $aTagData['text'][$iIndex], $sLanguageId); } $oTag->save(); }
public function getLanguageIdsOfStrings() { $aLanguages = TranslationQuery::create()->filterByStringKey('tag.' . $this->getName())->select('LanguageId')->find()->toArray(); if (is_array($aLanguages) && !empty($aLanguages)) { return $aLanguages; } return null; }
protected function getQuery($text, $from, $to) { $params = array('format' => 'json', 'action' => 'ttmserver', 'sourcelanguage' => $from, 'targetlanguage' => $to, 'text' => $text); if (isset($this->config['service'])) { $params['service'] = $this->config['service']; } return TranslationQuery::factory($this->config['url'])->timeout($this->config['timeout'])->queryParamaters($params); }
public function getCriteria() { $oQuery = TranslationQuery::create(); if ($this->oDelegateProxy->getNameSpace() === CriteriaListWidgetDelegate::SELECT_WITHOUT) { return $oQuery->filterByKeysWithoutNamespace(); } elseif ($this->oDelegateProxy->getNameSpace() !== CriteriaListWidgetDelegate::SELECT_ALL) { $oQuery->filterByNamespace($this->oDelegateProxy->getNameSpace()); } return $oQuery->groupByStringKey(); }
protected function getQuery($text, $from, $to) { if (!isset($this->config['key'])) { throw new TranslationWebServiceException('API key is not set'); } $text = trim($text); $text = $this->wrapUntranslatable($text); $params = array('q' => $text, 'langpair' => "{$from}|{$to}", 'x-application' => "Translate " . TRANSLATE_VERSION . ")"); return TranslationQuery::factory($this->config['url'])->timeout($this->config['timeout'])->queryParamaters($params); }
protected function getQuery($text, $from, $to) { if (!isset($this->config['host'])) { throw new TranslationWebServiceException('Cxserver host not set'); } $text = trim($text); $text = $this->wrapUntranslatable($text); $url = $this->config['host'] . "/v1/mt/{$from}/{$to}/Apertium"; return TranslationQuery::factory($url)->timeout($this->config['timeout'])->postWithData($text); }
public static function getCustomListElements() { if (count(TranslationPeer::getNamespaces()) > 0) { $aElements = array(array('name_space' => CriteriaListWidgetDelegate::SELECT_ALL, 'title' => TranslationPeer::getString('wns.strings.select_all_title'), 'magic_column' => 'all')); if (TranslationQuery::create()->filterByKeysWithoutNamespace()->count() > 0) { $aElementsWithout = array(array('name_space' => CriteriaListWidgetDelegate::SELECT_WITHOUT, 'title' => TranslationPeer::getString('wns.strings.select_without_title'), 'magic_column' => 'without')); $aElements = array_merge($aElements, $aElementsWithout); } return $aElements; } return array(); }
protected function getQuery($text, $from, $to) { if (!isset($this->config['key'])) { throw new TranslationWebServiceException('API key is not set'); } # http://api.yandex.com/translate/doc/dg/reference/translate.xml if (strlen($text) > 10000) { throw new TranslationWebServiceException('Source text too long'); } $service = $this->service; $text = trim($text); $text = $this->wrapUntranslatable($text); return TranslationQuery::factory($this->config['url'])->timeout($this->config['timeout'])->postWithData(array('key' => $this->config['key'], 'text' => $text, 'lang' => "{$from}-{$to}", 'format' => 'html')); }
/** * Список перевода для локали * * @param $locale * @return array */ public static function getListForLocale($locale) { $translation_list_en = array(); $translation_list_locale = array(); $result = array(); $translation_list = TranslationQuery::create()->joinWithI18n('en')->find(); foreach ($translation_list as $translation_item) { /** @var Translation $translation_item */ $translation_list_en[$translation_item->getId()]['alias'] = $translation_item->getAlias(); $translation_list_en[$translation_item->getId()]['title'] = $translation_item->getTitle(); } $translation_list = TranslationQuery::create()->joinWithI18n($locale)->find(); foreach ($translation_list as $translation_item) { /** @var Translation $translation_item */ $translation_list_locale[$translation_item->getId()] = $translation_item->getTitle(); } foreach ($translation_list_en as $id => $translation_item) { $result[$translation_item['alias']] = isset($translation_list_locale[$id]) && $translation_list_locale[$id] ? $translation_list_locale[$id] : ($translation_item['title'] ? $translation_item['title'] : $translation_item['alias']); } return $result; }
/** * Returns a new TranslationQuery object. * * @param string $modelAlias The alias of a model in the query * @param TranslationQuery|Criteria $criteria Optional Criteria to build the query from * * @return TranslationQuery */ public static function create($modelAlias = null, $criteria = null) { if ($criteria instanceof TranslationQuery) { return $criteria; } $query = new TranslationQuery(null, null, $modelAlias); if ($criteria instanceof Criteria) { $query->mergeWith($criteria); } return $query; }
protected function getQuery($text, $from, $to) { if (!isset($this->config['key'])) { throw new TranslationWebServiceException('API key is not set'); } $text = trim($text); $text = $this->wrapUntranslatable($text); $params = array('text' => $text, 'from' => $from, 'to' => $to, 'appId' => $this->config['key']); $url = 'http://api.microsofttranslator.com/V2/Http.svc/Translate?'; return TranslationQuery::factory($this->config['url'])->timeout($this->config['timeout'])->queryParamaters($params); }
public static function countNameSpaceByName($sNameSpace) { return TranslationQuery::create()->filterByStringKey("{$sNameSpace}.%", Criteria::LIKE)->count(); }
/** * Removes this object from datastore and sets delete attribute. * * @param PropelPDO $con * @return void * @throws PropelException * @throws Exception * @see BaseObject::setDeleted() * @see BaseObject::isDeleted() */ public function delete(PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getConnection(TranslationPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $deleteQuery = TranslationQuery::create()->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); // denyable behavior if (!(TranslationPeer::isIgnoringRights() || $this->mayOperate("delete"))) { throw new PropelException(new NotPermittedException("delete.by_role", array("role_key" => "languages"))); } if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (Exception $e) { $con->rollBack(); throw $e; } }
/** * Returns all translations for the given file. * * @param File $file * @param boolean $onlyUpdated * * @return array */ public function getTranslationsForFile($file, $onlyUpdated) { $query = TranslationQuery::create()->filterByFile($file)->joinWith('TransUnit'); if ($onlyUpdated) { $query->add(null, TranslationPeer::UPDATED_AT . '>' . TranslationPeer::CREATED_AT, \Criteria::CUSTOM); } $results = $query->select(array('Content', 'TransUnit.Key'))->orderBy(TranslationPeer::ID, \Criteria::ASC)->find(); $translations = array(); foreach ($results as $result) { $translations[$result['TransUnit.Key']] = $result['Content']; } return $translations; }
protected function getQuery($text, $from, $to) { if (!isset($this->config['key'])) { throw new TranslationWebServiceException('API key is not set'); } $text = trim($text); $text = $this->wrapUntranslatable($text); $params = array('q' => $text, 'key' => $this->config['key'], 'keyfrom' => $this->config['keyfrom'], 'type' => 'data', 'doctype' => 'xml', 'version' => '1.1'); $url = 'http://fanyi.youdao.com/openapi.do?'; return TranslationQuery::factory($this->config['url'])->timeout($this->config['timeout'])->queryParamaters($params); }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this Language is new, it will return * an empty collection; or if this Language has previously * been saved, it will retrieve related Translations from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in Language. * * @param Criteria $criteria optional Criteria object to narrow the query * @param PropelPDO $con optional connection object * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN) * @return PropelObjectCollection|Translation[] List of Translation objects */ public function getTranslationsJoinUserRelatedByUpdatedBy($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $query = TranslationQuery::create(null, $criteria); $query->joinWith('UserRelatedByUpdatedBy', $join_behavior); return $this->getTranslations($query, $con); }
public function saveData($aStringData) { $this->validate($aStringData); if (!Flash::noErrors()) { throw new ValidationException(); } $oConnection = Propel::getConnection(); foreach (LanguageQuery::create()->orderById()->find() as $oLanguage) { $oUpdateCriteria = new Criteria(); $oUpdateCriteria->add(TranslationPeer::LANGUAGE_ID, $oLanguage->getId()); $oUpdateCriteria->add(TranslationPeer::STRING_KEY, $this->sStringId); if (isset($aStringData['text_' . $oLanguage->getId()])) { $sText = trim($aStringData['text_' . $oLanguage->getId()]); $oString = TranslationQuery::create()->findPk(array($oLanguage->getId(), $this->sStringId)); if ($sText === '') { if ($oString !== null) { $oString->delete(); } continue; } if ($oString === null) { $oString = new Translation(); $oString->setLanguageId($oLanguage->getId()); $oString->setStringKey($aStringData['string_key']); } else { if ($this->sStringId !== null && $this->sStringId !== $aStringData['string_key']) { $oString->setStringKey($aStringData['string_key']); BasePeer::doUpdate($oUpdateCriteria, $oString->buildCriteria(), $oConnection); } } $oString->setText($sText); $oString->save(); } else { $oString = TranslationQuery::create()->findPk(array($oLanguage->getId(), $this->sStringId)); if ($oString === null) { continue; } if ($this->sStringId !== null && $this->sStringId !== $aStringData['string_key']) { $oString->setStringKey($aStringData['string_key']); BasePeer::doUpdate($oUpdateCriteria, $oString->buildCriteria(), $oConnection); } } } // check sidebar reload criteria $sNameSpaceOld = TranslationPeer::getNameSpaceFromStringKey($this->sStringId); $sNameSpaceNew = TranslationPeer::getNameSpaceFromStringKey($aStringData['string_key']); // if both are the same the sidebar is not effected $bSidebarHasChanged = false; if ($sNameSpaceOld !== $sNameSpaceNew) { // if there was an old name space then we have to check whether it was the last string with this namespace if ($sNameSpaceOld !== null && !TranslationPeer::nameSpaceExists($sNameSpaceOld)) { $bSidebarHasChanged = true; } // if the new exits only once it has been created and the sidebar needs to be relaoded if ($sNameSpaceNew !== null && TranslationPeer::countNameSpaceByName($sNameSpaceNew) === 1) { $bSidebarHasChanged = true; } } $this->sStringId = $aStringData['string_key']; return array('id' => $this->sStringId, self::SIDEBAR_CHANGED => $bSidebarHasChanged); }
/** * @return \DateTime|null */ public function getLatestTranslationUpdatedAt() { $result = TranslationQuery::create()->withColumn(sprintf('MAX(%s)', TranslationPeer::UPDATED_AT), 'max_updated_at')->select(array('max_updated_at'))->findOne($this->getConnection()); return !empty($result) ? new \DateTime($result) : null; }
/** * Register a query to be run. * @param TranslationQuery $query * @return mixed Query id that can be used to fetch results. */ public function addQuery(TranslationQuery $query) { $this->queries[] = $query; $this->timeout = max($query->getTimeout(), $this->timeout); return count($this->queries) - 1; }