From 261806109d8d4f591b50487c0c655ad3aaf73d31 Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Thu, 4 Dec 2014 11:42:21 +0000 Subject: [PATCH] Add/Edit/View Project languages --- PHPCI/Controller/ProjectController.php | 64 +++++++++++++------------- PHPCI/Helper/Lang.php | 14 +++--- PHPCI/Languages/lang.en-gb.php | 38 +++++++++++++++ PHPCI/View/Build/header-row.phtml | 7 +-- PHPCI/View/ProjectForm.phtml | 5 +- 5 files changed, 85 insertions(+), 43 deletions(-) diff --git a/PHPCI/Controller/ProjectController.php b/PHPCI/Controller/ProjectController.php index 69d8b95e..c8bfd2a4 100644 --- a/PHPCI/Controller/ProjectController.php +++ b/PHPCI/Controller/ProjectController.php @@ -17,6 +17,7 @@ use b8\Exception\HttpException\NotFoundException; use b8\Store; use PHPCI\BuildFactory; use PHPCI\Helper\Github; +use PHPCI\Helper\Lang; use PHPCI\Helper\SshKey; use PHPCI\Model\Build; use PHPCI\Model\Project; @@ -68,7 +69,7 @@ class ProjectController extends \PHPCI\Controller $project = $this->projectStore->getById($projectId); if (empty($project)) { - throw new NotFoundException('Project with id: ' . $projectId . ' not found'); + throw new NotFoundException(Lang::get('project_x_not_found', $projectId)); } $per_page = 10; @@ -77,7 +78,8 @@ class ProjectController extends \PHPCI\Controller $pages = $builds[1] == 0 ? 1 : ceil($builds[1] / $per_page); if ($page > $pages) { - throw new NotFoundException('Page with number: ' . $page . ' not found'); + header('Location: '.PHPCI_URL.'project/view/'.$projectId); + die; } $this->view->builds = $builds[0]; @@ -107,7 +109,7 @@ class ProjectController extends \PHPCI\Controller } if (empty($project)) { - throw new NotFoundException('Project with id: ' . $projectId . ' not found'); + throw new NotFoundException(Lang::get('project_x_not_found', $projectId)); } $email = $_SESSION['phpci_user']->getEmail(); @@ -174,7 +176,7 @@ class ProjectController extends \PHPCI\Controller */ public function add() { - $this->layout->title = 'Add Project'; + $this->layout->title = Lang::get('add_project'); $this->requireAdmin(); $method = $this->request->getMethod(); @@ -231,10 +233,11 @@ class ProjectController extends \PHPCI\Controller $project = $this->projectStore->getById($projectId); if (empty($project)) { - throw new NotFoundException('Project with id: ' . $projectId . ' not found'); + throw new NotFoundException(Lang::get('project_x_not_found', $projectId)); } - $this->config->set('page_title', 'Edit: ' . $project->getTitle()); + $this->layout->title = $project->getTitle(); + $this->layout->subtitle = Lang::get('edit_project'); $values = $project->getDataArray(); $values['key'] = $values['ssh_private_key']; @@ -262,7 +265,7 @@ class ProjectController extends \PHPCI\Controller return $view->render(); } - $title = $this->getParam('title', 'New Project'); + $title = $this->getParam('title', Lang::get('new_project')); $reference = $this->getParam('reference', null); $type = $this->getParam('type', null); @@ -292,16 +295,16 @@ class ProjectController extends \PHPCI\Controller $form->addField(new Form\Element\Hidden('pubkey')); $options = array( - 'choose' => 'Select repository type...', - 'github' => 'Github', - 'bitbucket' => 'Bitbucket', - 'gitlab' => 'Gitlab', - 'remote' => 'Remote URL', - 'local' => 'Local Path', - 'hg' => 'Mercurial', + 'choose' => Lang::get('select_repository_type'), + 'github' => Lang::get('github'), + 'bitbucket' => Lang::get('bitbucket'), + 'gitlab' => Lang::get('gitlab'), + 'remote' => Lang::get('remote'), + 'local' => Lang::get('local'), + 'hg' => Lang::get('hg'), ); - $field = Form\Element\Select::create('type', 'Where is your project hosted?', true); + $field = Form\Element\Select::create('type', Lang::get('where_hosted'), true); $field->setPattern('^(github|bitbucket|gitlab|remote|local|hg)'); $field->setOptions($options); $field->setClass('form-control')->setContainerClass('form-group'); @@ -310,45 +313,42 @@ class ProjectController extends \PHPCI\Controller $container = new Form\ControlGroup('github-container'); $container->setClass('github-container'); - $field = Form\Element\Select::create('github', 'Choose a Github repository:', false); + $field = Form\Element\Select::create('github', Lang::get('choose_github'), false); $field->setClass('form-control')->setContainerClass('form-group'); $container->addField($field); $form->addField($container); - $field = Form\Element\Text::create('reference', 'Repository Name / URL (Remote) or Path (Local)', true); + $field = Form\Element\Text::create('reference', Lang::get('repo_name'), true); $field->setValidator($this->getReferenceValidator($values)); $field->setClass('form-control')->setContainerClass('form-group'); $form->addField($field); - $field = Form\Element\Text::create('title', 'Project Title', true); + $field = Form\Element\Text::create('title', Lang::get('project_title'), true); $field->setClass('form-control')->setContainerClass('form-group'); $form->addField($field); - $title = 'Private key to use to access repository (leave blank for local and/or anonymous remotes)'; - $field = Form\Element\TextArea::create('key', $title, false); + $field = Form\Element\TextArea::create('key', Lang::get('project_private_key'), false); $field->setClass('form-control')->setContainerClass('form-group'); $field->setRows(6); $form->addField($field); - $label = 'PHPCI build config for this project (if you cannot add a phpci.yml file in the project repository)'; - $field = Form\Element\TextArea::create('build_config', $label, false); + $field = Form\Element\TextArea::create('build_config', Lang::get('build_config'), false); $field->setClass('form-control')->setContainerClass('form-group'); $field->setRows(6); $form->addField($field); - $field = Form\Element\Text::create('branch', 'Default branch name', true); + $field = Form\Element\Text::create('branch', Lang::get('default_branch'), true); $field->setClass('form-control')->setContainerClass('form-group')->setValue('master'); $form->addField($field); - $label = 'Enable public status page and image for this project?'; - $field = Form\Element\Checkbox::create('allow_public_status', $label, false); + $field = Form\Element\Checkbox::create('allow_public_status', Lang::get('allow_public_status'), false); $field->setContainerClass('form-group'); $field->setCheckedValue(1); $field->setValue(0); $form->addField($field); $field = new Form\Element\Submit(); - $field->setValue('Save Project'); + $field->setValue(Lang::get('save_project')); $field->setContainerClass('form-group'); $field->setClass('btn-success'); $form->addField($field); @@ -374,30 +374,30 @@ class ProjectController extends \PHPCI\Controller $validators = array( 'hg' => array( 'regex' => '/^(https?):\/\//', - 'message' => 'Mercurial repository URL must be start with http:// or https://' + 'message' => Lang::get('error_mercurial') ), 'remote' => array( 'regex' => '/^(git|https?):\/\//', - 'message' => 'Repository URL must be start with git://, http:// or https://' + 'message' => Lang::get('error_remote') ), 'gitlab' => array( 'regex' => '`^(.*)@(.*):(.*)/(.*)\.git`', - 'message' => 'GitLab Repository name must be in the format "user@domain.tld:owner/repo.git"' + 'message' => Lang::get('error_gitlab') ), 'github' => array( 'regex' => '/^[a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-\.]+$/', - 'message' => 'Repository name must be in the format "owner/repo"' + 'message' => Lang::get('error_github') ), 'bitbucket' => array( 'regex' => '/^[a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-\.]+$/', - 'message' => 'Repository name must be in the format "owner/repo"' + 'message' => Lang::get('error_bitbucket') ), ); if (in_array($type, $validators) && !preg_match($validators[$type]['regex'], $val)) { throw new \Exception($validators[$type]['message']); } elseif ($type == 'local' && !is_dir($val)) { - throw new \Exception('The path you specified does not exist.'); + throw new \Exception(Lang::get('error_path')); } return true; diff --git a/PHPCI/Helper/Lang.php b/PHPCI/Helper/Lang.php index dc612513..084c359b 100644 --- a/PHPCI/Helper/Lang.php +++ b/PHPCI/Helper/Lang.php @@ -42,14 +42,16 @@ class Lang public static function init(Config $config) { // Try user language: - $matches = array(); + if (isset($_SERVER) && array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)) { + $matches = array(); - if (preg_match('/([a-zA-Z]{2}\-[a-zA-Z]{2})/', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches)) { - self::$language = strtolower($matches[1]); - self::$strings = self::loadLanguage(); + if (preg_match('/([a-zA-Z]{2}\-[a-zA-Z]{2})/', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches)) { + self::$language = strtolower($matches[1]); + self::$strings = self::loadLanguage(); - if (!is_null(self::$strings)) { - return; + if (!is_null(self::$strings)) { + return; + } } } diff --git a/PHPCI/Languages/lang.en-gb.php b/PHPCI/Languages/lang.en-gb.php index 0eaeb261..3b9b7b04 100644 --- a/PHPCI/Languages/lang.en-gb.php +++ b/PHPCI/Languages/lang.en-gb.php @@ -14,6 +14,9 @@ $strings = array( 'n_builds_running' => '%d builds running', 'edit_profile' => 'Edit Profile', 'sign_out' => 'Sign Out', + 'branch_x' => 'Branch: %s', + 'created_x' => 'Created: %s', + 'started_x' => 'Started: %s', // Sidebar 'hello_name' => 'Hello, %s', @@ -49,4 +52,39 @@ $strings = array( 'started' => 'Started', 'successful' => 'Successful', 'failed' => 'Failed', + + // Add/Edit Project: + 'new_project' => 'New Project', + 'project_x_not_found' => 'Project with ID %d does not exist.', + 'project_details' => 'Project Details', + 'public_key_help' => 'To make it easier to get started, we\'ve generated an SSH key pair for you to use + for this project. To use it, just add the following public key to the "deploy keys" section + of your chosen source code hosting platform.', + 'select_repository_type' => 'Select repository type...', + 'github' => 'Github', + 'bitbucket' => 'Bitbucket', + 'gitlab' => 'Gitlab', + 'remote' => 'Remote URL', + 'local' => 'Local Path', + 'hg' => 'Mercurial', + + 'where_hosted' => 'Where is your project hosted?', + 'choose_github' => 'Choose a Github repository:', + + 'repo_name' => 'Repository Name / URL (Remote) or Path (Local)', + 'project_title' => 'Project Title', + 'project_private_key' => 'Private key to use to access repository + (leave blank for local and/or anonymous remotes)', + 'build_config' => 'PHPCI build config for this project + (if you cannot add a phpci.yml file in the project repository)', + 'default_branch' => 'Default branch name', + 'allow_public_status' => 'Enable public status page and image for this project?', + 'save_project' => 'Save Project', + + 'error_mercurial' => 'Mercurial repository URL must be start with http:// or https://', + 'error_remote' => 'Repository URL must be start with git://, http:// or https://', + 'error_gitlab' => 'GitLab Repository name must be in the format "user@domain.tld:owner/repo.git"', + 'error_github' => 'Repository name must be in the format "owner/repo"', + 'error_bitbucket' => 'Repository name must be in the format "owner/repo"', + 'error_path' => 'The path you specified does not exist.', ); \ No newline at end of file diff --git a/PHPCI/View/Build/header-row.phtml b/PHPCI/View/Build/header-row.phtml index 83bd4524..b0559da0 100644 --- a/PHPCI/View/Build/header-row.phtml +++ b/PHPCI/View/Build/header-row.phtml @@ -1,3 +1,4 @@ +
  • getCommitterEmail()): ?> @@ -10,11 +11,11 @@ getProject()->getTitle(); ?> getStatus() == \PHPCI\Model\Build::STATUS_NEW): ?> - Created getCreated()->format('g:ia'); ?> + getCreated()->format('H:i')); ?> getStatus() == \PHPCI\Model\Build::STATUS_RUNNING): ?> - Started getStarted()->format('g:ia'); ?> + getStarted()->format('H:i')); ?> -

    Branch: getBranch(); ?>

    +

    getBranch()); ?>

  • \ No newline at end of file diff --git a/PHPCI/View/ProjectForm.phtml b/PHPCI/View/ProjectForm.phtml index a7a5abd6..5accf682 100644 --- a/PHPCI/View/ProjectForm.phtml +++ b/PHPCI/View/ProjectForm.phtml @@ -1,9 +1,10 @@ +
    -

    Project Details

    +

    @@ -16,7 +17,7 @@
    -

    To make it easier to get started, we've generated a public / private key pair for you to use for this project. To use it, just add the following public key to the "deploy keys" section of your repository settings on Github / Bitbucket.

    +