本文整理汇总了PHP中Repository::getDefaultLanguage方法的典型用法代码示例。如果您正苦于以下问题:PHP Repository::getDefaultLanguage方法的具体用法?PHP Repository::getDefaultLanguage怎么用?PHP Repository::getDefaultLanguage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Repository
的用法示例。
在下文中一共展示了Repository::getDefaultLanguage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: exportRepository
/**
* Exports the given repository and creates a ZIP file containing XML output files
*
* @param Repository $repository the Repository instance to export
* @param string $filename the output file name inside each language folder
* @param int $groupID the group to get the output for (or Phrase::GROUP_ALL)
* @param int $format the format (constant) to use for this export
* @param int $minCompletion the minimum percentage of completion for languages to be eligible for exporting
* @param bool $ignoreIfSameAsDefault ignore phrases which are the same as the default language
* @throws Exception if the repository could not be exported
*/
public static function exportRepository($repository, $filename, $groupID, $format, $minCompletion = 0, $ignoreIfSameAsDefault = false)
{
if (self::isFilenameValid($filename)) {
if ($repository instanceof Repository) {
$exportSuccess = true;
$randomDir = mt_rand(1000000, 9999999);
$savePath = URL::getTempPath(false) . URL::encodeID($repository->getID());
self::deleteDirectoryRecursively($savePath);
// delete all old output files from output directory first
$savePath .= '/' . $randomDir;
// navigate to random directory inside output folder
if (mkdir($savePath, 0755, true)) {
// if output folder could be created
$languages = Language::getList();
$defaultLanguageObject = $repository->getLanguage($repository->getDefaultLanguage());
foreach ($languages as $language) {
$languageObject = $repository->getLanguage($language);
$languageKeys = $languageObject->getKeys();
$ignorePhrasesSameAsDefault = $ignoreIfSameAsDefault && $repository->getDefaultLanguage() != $language;
if ($format == self::FORMAT_ANDROID_XML_ESCAPED_HTML) {
$languageOutput = $languageObject->outputAndroidXMLEscapedHTML($groupID, $ignorePhrasesSameAsDefault, $defaultLanguageObject);
$fileExtension = '.xml';
} elseif ($format == self::FORMAT_JSON) {
$languageOutput = $languageObject->outputJSON($groupID, $ignorePhrasesSameAsDefault, $defaultLanguageObject);
$fileExtension = '.json';
} elseif ($format == self::FORMAT_PLAINTEXT) {
$languageOutput = $languageObject->outputPlaintext($groupID, $ignorePhrasesSameAsDefault, $defaultLanguageObject);
$fileExtension = '.txt';
} else {
$languageOutput = $languageObject->outputAndroidXML($groupID, $ignorePhrasesSameAsDefault, $defaultLanguageObject);
$fileExtension = '.xml';
}
if ($languageOutput->getCompleteness() >= $minCompletion) {
foreach ($languageKeys as $languageKey) {
if (mkdir($savePath . '/' . $languageKey . '/', 0755, true)) {
if (file_put_contents($savePath . '/' . $languageKey . '/' . $filename . $fileExtension, $languageOutput->getContent()) !== false) {
$exportSuccess = true;
} else {
// output file could not be written
$exportSuccess = false;
}
} else {
// sub-directory for language could not be created
$exportSuccess = false;
}
}
}
}
} else {
// output folder could not be created
$exportSuccess = false;
}
if ($exportSuccess) {
$outputPath = URL::getTempPath(true) . URL::encodeID($repository->getID()) . '/' . $randomDir;
if (self::zipFolder($savePath, $savePath . '/Export.zip')) {
UI::redirectToURL($outputPath . '/Export.zip');
}
}
} else {
throw new Exception('The repository must be an instance of class Repository');
}
} else {
throw new Exception('Invalid filename: ' . $filename);
}
}
示例2: getPage_Project
public static function getPage_Project($contents, $containers)
{
$page = self::getDataGET('p');
$repositoryID = self::validateID(self::getDataGET('project'), true);
$languageID = self::validateID(self::getDataGET('language'), true);
$isAddingMode = isset($page) && $page == 'add_phrase';
$isExportMode = isset($page) && $page == 'export';
$isImportMode = isset($page) && $page == 'import';
$repositoryData = Database::getRepositoryData($repositoryID);
$languageData = Database::getLanguageData($languageID);
if (empty($repositoryData)) {
self::addBreadcrumbItem(URL::toProject($repositoryID), 'Project not found');
self::setTitle('Project not found');
$contents[] = new UI_Heading('Project not found', true);
$contents[] = new UI_Paragraph('We\'re sorry, but we could not find the project 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']));
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 {
$defaultLanguage = new Language_Android($repository->getDefaultLanguage());
if ($isAddingMode) {
$formTargetURL = URL::toAddPhrase($repositoryID, $languageID);
self::addBreadcrumbItem($formTargetURL, 'Add phrase');
$form = new UI_Form($formTargetURL, false);
$radioType = new UI_Form_Radio('Phrase type', 'add_phrase[type]');
$radioType->addOption('<abbr title="Resource type for single phrases">string</abbr>', 1, 'addPhraseTypeSelect(\'addPhraseGroup_String\');');
$radioType->addOption('<abbr title="Resource type for arrays of phrases">string-array</abbr>', 2, 'addPhraseTypeSelect(\'addPhraseGroup_StringArray\');');
$radioType->addOption('<abbr title="Resource type for quantity strings">plurals</abbr>', 3, 'addPhraseTypeSelect(\'addPhraseGroup_Plurals\');');
$form->addContent($radioType);
$textPhraseKey = new UI_Form_Text('Key', 'add_phrase[key]', 'Unique identifier', false, 'This is the short string that you\'ll identify the phrase(s) with later.');
$form->addContent($textPhraseKey);
$textPhraseStringValue = new UI_Form_Textarea('String', 'add_phrase[string]', 'String for ' . $defaultLanguage->getNameFull(), 'You can later translate this string to other languages.', false, '', 2, $defaultLanguage->isRTL(), '', 'addPhraseGroup_String');
$form->addContent($textPhraseStringValue);
$textPhraseStringArrayValue = new UI_Form_Textarea('Item', 'add_phrase[string_array][]', 'Item for ' . $defaultLanguage->getNameFull(), 'You can later translate this item to other languages.', false, '', 2, $defaultLanguage->isRTL(), '', 'addPhraseGroup_StringArray', 'display:none;', false);
$form->addContent($textPhraseStringArrayValue);
$quantities = Phrase_Android_Plurals::getList();
foreach ($quantities as $quantity) {
$textPhrasePluralsValue = new UI_Form_Textarea($quantity, 'add_phrase[plurals][' . $quantity . ']', 'Quantity for ' . $defaultLanguage->getNameFull(), 'You can later translate this quantity to other languages.', false, '', 2, $defaultLanguage->isRTL(), '', 'addPhraseGroup_Plurals', 'display:none;');
$form->addContent($textPhrasePluralsValue);
}
$buttonSubmit = new UI_Form_Button('Save phrase(s)', UI_Link::TYPE_SUCCESS);
$buttonAddItem = new UI_Link('Add item', '#', UI_Link::TYPE_INFO, 'addPhraseGroup_StringArray', 'display:none;', 'addPhraseAddItem(\'add_phrase[string_array][]\'); return false;');
$buttonCancel = new UI_Link('Cancel', URL::toLanguage($repositoryID, $languageID), UI_Link::TYPE_UNIMPORTANT);
$form->addContent(new UI_Form_ButtonGroup(array($buttonSubmit, $buttonAddItem, $buttonCancel)));
self::setTitle('Add phrase to default language');
$contents[] = new UI_Heading('Add phrase to default language', true);
$contents[] = $form;
} elseif ($isExportMode) {
$formTargetURL = URL::toExport($repositoryID);
self::addBreadcrumbItem($formTargetURL, 'Export');
$form = new UI_Form($formTargetURL, false);
$textFilename = new UI_Form_Text('Filename', 'export[filename]', 'strings', false, 'Please choose a filename (without extension) for the output files that will be exported inside each language folder.');
$textFilename->setDefaultValue('strings');
$form->addContent($textFilename);
$selectGroupID = new UI_Form_Select('Phrase groups', 'export[groupID]', 'Do you want to export all phrases or only a single group?');
$selectGroupID->addOption('(All groups)', Phrase::GROUP_ALL);
$selectGroupID->addOption('(Default group)', Phrase::GROUP_NONE);
$phraseGroups = Database::getPhraseGroups($repositoryID, $repositoryData['defaultLanguage'], false);
foreach ($phraseGroups as $phraseGroup) {
$selectGroupID->addOption($phraseGroup['name'], $phraseGroup['id']);
}
$form->addContent($selectGroupID);
$selectMinCompletion = new UI_Form_Select('Minimum completion', 'export[minCompletion]', 'You can either export all languages or only those with a given minimum completion.');
$selectMinCompletion->addOption('Export all languages', 0);
$selectMinCompletion->addOption('5% completion or more', 5);
$selectMinCompletion->addOption('10% completion or more', 10);
$selectMinCompletion->addOption('25% completion or more', 25);
$selectMinCompletion->addOption('50% completion or more', 50);
$selectMinCompletion->addOption('75% completion or more', 75);
$selectMinCompletion->addOption('100% completion or more', 100);
$form->addContent($selectMinCompletion);
$selectFormat = new UI_Form_Select('Output format', 'export[format]', 'Which output format do you want to export in? When developing for Android, you should usually keep the default choice.');
$selectFormat->addOption('Android XML', File_IO::FORMAT_ANDROID_XML);
$selectFormat->addOption('Android XML with escaped HTML', File_IO::FORMAT_ANDROID_XML_ESCAPED_HTML);
$selectFormat->addOption('JSON', File_IO::FORMAT_JSON);
$selectFormat->addOption('Plaintext', File_IO::FORMAT_PLAINTEXT);
$form->addContent($selectFormat);
$ignoreIfSameAsDefault = new UI_Form_Select('Exclude defaults', 'export[ignoreIfSameAsDefault]', 'Do you want to exclude phrases which are the same as the respective phrase in the default language?');
$ignoreIfSameAsDefault->addOption('No, export a complete file for each language', 0);
$ignoreIfSameAsDefault->addOption('Yes, export only what\'s necessary', 1);
$form->addContent($ignoreIfSameAsDefault);
$isAdmin = Repository::hasUserPermissions(Authentication::getUserID(), $repositoryID, $repositoryData, Repository::ROLE_ADMINISTRATOR);
$buttonSubmit = new UI_Form_Button('Export', UI_Link::TYPE_SUCCESS);
$buttonManageGroups = new UI_Link('Manage groups', URL::toEditProject($repositoryID, true), UI_Link::TYPE_UNIMPORTANT);
$buttonCancel = new UI_Link('Cancel', URL::toProject($repositoryID), UI_Link::TYPE_UNIMPORTANT);
if ($isAdmin) {
$form->addContent(new UI_Form_ButtonGroup(array($buttonSubmit, $buttonManageGroups, $buttonCancel)));
} else {
//.........这里部分代码省略.........