public function addPhrase($language, $id, $phraseKey, $payload, $groupID, $enabled = true, $createKeysOnly = false, $isUsingDefaultPhrase = false) { $this->languages[$language]->addPhrase(Phrase::create($id, $phraseKey, $payload, $groupID, $enabled, $createKeysOnly, $isUsingDefaultPhrase)); }
public static function approveEditsByContributor($repositoryID, $languageID, $contributorID) { $edits = self::getPendingEditsByRepositoryLanguageAndUser($repositoryID, $languageID, $contributorID); foreach ($edits as $edit) { $previousPhraseData = Database::getPhrase($repositoryID, $languageID, $edit['phraseKey']); if (empty($previousPhraseData)) { $phraseObject = Phrase::create(0, $edit['phraseKey'], $edit['payload'], 0, true); } else { $phraseObject = Phrase::create(0, $edit['phraseKey'], $previousPhraseData['payload'], 0); } $phraseObject->setPhraseValue($edit['phraseSubKey'], $edit['suggestedValue']); self::updatePhrase($repositoryID, $languageID, $edit['phraseKey'], $phraseObject->getPayload()); self::updateContributor($repositoryID, $edit['userID']); self::deleteEdit($edit['id']); } Authentication::setCachedLanguageProgress($repositoryID, NULL); // unset cached version of this repository's progress }
public static function getPage_Phrase($contents, $containers) { $repositoryID = self::validateID(self::getDataGET('project'), true); $languageID = self::validateID(self::getDataGET('language'), true); $phraseID = self::validateID(self::getDataGET('phrase'), true); $repositoryData = Database::getRepositoryData($repositoryID); $phraseData = Database::getPhraseData($repositoryID, $phraseID); if (empty($repositoryData) || empty($phraseData)) { self::addBreadcrumbItem(URL::toProject($repositoryID), 'Phrase not found'); self::setTitle('Phrase not found'); $contents[] = new UI_Heading('Phrase not found', true); $contents[] = new UI_Paragraph('We\'re sorry, but we could not find the phrase that you requested.'); $contents[] = new UI_Paragraph('Please check if you have made any typing errors.'); } else { self::addBreadcrumbItem(URL::toProject($repositoryID), htmlspecialchars($repositoryData['name'])); self::addBreadcrumbItem(URL::toLanguage($repositoryID, $languageID), Language::getLanguageNameFull($languageID)); Authentication::saveCachedRepository($repositoryID, $repositoryData['name']); $repository = new Repository($repositoryID, $repositoryData['name'], $repositoryData['visibility'], $repositoryData['defaultLanguage']); $role = Database::getRepositoryRole(Authentication::getUserID(), $repositoryID); $permissions = $repository->getPermissions(Authentication::getUserID(), $role); if (Authentication::getUserID() <= 0) { self::setTitle($repositoryData['name']); $contents[] = new UI_Heading(htmlspecialchars($repositoryData['name']), true); $contents[] = self::getLoginForm(); } elseif ($permissions->isInvitationMissing()) { self::setTitle($repositoryData['name']); $contents[] = new UI_Heading(htmlspecialchars($repositoryData['name']), true); $contents[] = self::getInvitationForm($repositoryID); } else { $mayMovePhrases = Repository::isRoleAllowedToMovePhrases($role); $currentPageURL = URL::toPhraseDetails($repositoryID, $languageID, $phraseID); self::addBreadcrumbItem($currentPageURL, $phraseData['phraseKey']); $phraseObject = Phrase::create($phraseID, $phraseData['phraseKey'], $phraseData['payload']); $phraseObjectEntries = $phraseObject->getPhraseValues(); $phraseEntries = new UI_List(); foreach ($phraseObjectEntries as $phraseObjectEntry) { $phraseEntries->addItem(nl2br(htmlspecialchars($phraseObjectEntry))); } if ($mayMovePhrases) { $formMove = new UI_Form($currentPageURL, false); $formMove->addContent(new UI_Form_Hidden('phraseMove[phraseKey]', $phraseData['phraseKey'])); $phraseGroupSelection = new UI_Form_Select('New group', 'phraseMove[groupID]'); $phraseGroupSelection->addOption('(Default group)', Phrase::GROUP_NONE); $phraseGroups = Database::getPhraseGroups($repositoryID, $repositoryData['defaultLanguage']); foreach ($phraseGroups as $phraseGroup) { $phraseGroupSelection->addOption($phraseGroup['name'], $phraseGroup['id']); } $phraseGroupSelection->addDefaultOption($phraseData['groupID']); $formMove->addContent($phraseGroupSelection); $formButtonList = array(new UI_Form_Button('Update group', UI_Link::TYPE_SUCCESS), new UI_Link('Manage groups', URL::toEditProject($repositoryID, true), UI_Link::TYPE_UNIMPORTANT), new UI_Link('Cancel', URL::toLanguage($repositoryID, $languageID), UI_Link::TYPE_UNIMPORTANT)); $formMove->addContent(new UI_Form_ButtonGroup($formButtonList)); } else { $formMove = NULL; } if ($mayMovePhrases) { $formChange = new UI_Form($currentPageURL, false); $formChange->addContent(new UI_Form_Hidden('phraseChange[phraseKey]', $phraseData['phraseKey'])); $actionTypeSelection = new UI_Form_Select('Operation', 'phraseChange[action]'); $actionTypeSelection->addOption('— Please choose —', ''); $actionTypeSelection->addOption('Untranslate: Remove all translations of this phrase only', 'untranslate'); $actionTypeSelection->addOption('Delete: Completely remove this phrase from the project', 'delete'); $formChange->addContent($actionTypeSelection); $formButtonList = array(new UI_Form_Button('Execute', UI_Link::TYPE_DANGER, UI_Form_Button::ACTION_SUBMIT, '', '', 'return confirm(\'Are you sure you want to execute the selected operation? This cannot be undone!\');'), new UI_Link('Cancel', URL::toLanguage($repositoryID, $languageID), UI_Link::TYPE_UNIMPORTANT)); $formChange->addContent(new UI_Form_ButtonGroup($formButtonList)); } else { $formChange = NULL; } self::setTitle('Phrase: ' . $phraseData['phraseKey']); $contents[] = new UI_Heading('Phrase: ' . $phraseData['phraseKey'], true); $contents[] = new UI_Heading('Contents', false, 3); $contents[] = $phraseEntries; if (isset($formMove)) { $contents[] = new UI_Heading('Move phrase to another group', false, 3); $contents[] = $formMove; } if (isset($formChange)) { $contents[] = new UI_Heading('Untranslate or delete phrase', false, 3); $contents[] = $formChange; } } } $cell = new UI_Cell($contents); $row = new UI_Row(array($cell)); $containers[] = new UI_Container(array($row)); return new UI_Group($containers); }