Dashboard updated to support languages

This commit is contained in:
Dan Cryer 2014-12-04 11:14:04 +00:00
parent 56bbf13f34
commit f6e433a94d
8 changed files with 141 additions and 83 deletions

View file

@ -11,6 +11,7 @@ namespace PHPCI\Controller;
use b8;
use PHPCI\BuildFactory;
use PHPCI\Helper\Lang;
use PHPCI\Model\Build;
/**
@ -42,7 +43,7 @@ class HomeController extends \PHPCI\Controller
*/
public function index()
{
$this->layout->title = 'Dashboard';
$this->layout->title = Lang::get('dashboard');
$projects = $this->projectStore->getWhere(array(), 50, 0, array(), array('title' => 'ASC'));

View file

@ -29,6 +29,11 @@ class Lang
return '%%MISSING STRING: ' . $string . '%%';
}
public static function out()
{
print call_user_func_array(array('PHPCI\Helper\Lang', 'get'), func_get_args());
}
public static function getStrings()
{
return self::$strings;
@ -36,13 +41,32 @@ class Lang
public static function init(Config $config)
{
self::$language = $config->get('phpci.default_language', 'en');
self::$strings = self::loadLanguage();
// Try user language:
$matches = array();
if (is_null(self::$strings)) {
self::$language = 'en';
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;
}
}
// Try the installation default language:
self::$language = $config->get('phpci.default_language', null);
if (!is_null(self::$language)) {
self::$strings = self::loadLanguage();
if (!is_null(self::$strings)) {
return;
}
}
// Fall back to en-GB:
self::$language = 'en-gb';
self::$strings = self::loadLanguage();
}
protected static function loadLanguage()

View file

@ -0,0 +1,52 @@
<?php
/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2014, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link https://www.phptesting.org/
*/
$strings = array(
// Top Nav
'toggle_navigation' => 'Toggle Navigation',
'n_builds_pending' => '%d builds pending',
'n_builds_running' => '%d builds running',
'edit_profile' => 'Edit Profile',
'sign_out' => 'Sign Out',
// Sidebar
'hello_name' => 'Hello, %s',
'dashboard' => 'Dashboard',
'admin_options' => 'Admin Options',
'add_project' => 'Add Project',
'settings' => 'Settings',
'manage_users' => 'Manage Users',
'plugins' => 'Plugins',
'view' => 'View',
'build_now' => 'Build Now',
'edit_project' => 'Edit Project',
'delete_project' => 'Delete Project',
// Dashboard:
'dashboard' => 'Dashboard',
// Project Summary:
'no_builds_yet' => 'No builds yet!',
'x_of_x_failed' => '%d out of the last %d builds failed.',
'x_of_x_failed_short' => '%d / %d failed.',
'last_successful_build' => ' The last successful build was %s.',
'never_built_successfully' => ' This project has never built successfully.',
'all_builds_passed' => 'All of the last %d builds passed.',
'all_builds_passed_short' => '%d / %d passed.',
'last_failed_build' => ' The last failed build was %s.',
'never_failed_build' => ' This project has never failed a build.',
'view_project' => 'View Project',
// Timeline:
'latest_builds' => 'Latest Builds',
'created' => 'Created',
'started' => 'Started',
'successful' => 'Successful',
'failed' => 'Failed',
);

View file

@ -7,8 +7,4 @@
* @link https://www.phptesting.org/
*/
$strings = array(
'toggle_navigation' => 'Toggle Navigation',
'n_builds_pending' => '%d builds pending',
'n_builds_running' => '%d builds running',
);
require_once(dirname(__FILE__) . '/lang.en-gb.php');

View file

@ -1,3 +1,4 @@
<?php use PHPCI\Helper\Lang; ?>
<div class="row">
<div class="col-sm-5">
@ -7,7 +8,7 @@
<div class="col-sm-7 pull-left">
<div class="box box-primary">
<div class="box-header">
<h3 class="box-title">Latest Builds</h3>
<h3 class="box-title"><?php Lang::out('latest_builds'); ?></h3>
</div>
<div class="box-body">
@ -20,25 +21,25 @@
switch ($build->getStatus()) {
case \PHPCI\Model\Build::STATUS_NEW:
$updated = $build->getCreated();
$label = 'Created';
$label = Lang::get('created');
$color = 'blue';
break;
case \PHPCI\Model\Build::STATUS_RUNNING:
$updated = $build->getStarted();
$label = 'Started';
$label = Lang::get('started');
$color = 'yellow';
break;
case \PHPCI\Model\Build::STATUS_SUCCESS:
$updated = $build->getFinished();
$label = 'Successful';
$label = Lang::get('successful');
$color = 'green';
break;
case \PHPCI\Model\Build::STATUS_FAILED:
$updated = $build->getFinished();
$label = 'Failed';
$label = Lang::get('failed');
$color = 'red';
break;
}
@ -57,7 +58,7 @@
<li>
<i class="fa fa-<?php print $build->getProject()->getIcon(); ?> bg-<?php print $color; ?>"></i>
<div class="timeline-item">
<span class="time"><i class="fa fa-clock-o"></i> <?php print $updated->format('g:ia'); ?></span>
<span class="time"><i class="fa fa-clock-o"></i> <?php print $updated->format('H:i'); ?></span>
<h3 class="timeline-header">
<a href="<?php print PHPCI_URL; ?>project/view/<?php print $build->getProjectId(); ?>">
<?php print $build->getProject()->getTitle(); ?>

View file

@ -1,10 +1,10 @@
<?php
use PHPCI\Helper\Lang;
foreach($projects as $project):
$statuses = array();
$successes = 0;
$failures = 0;
$health = '';
$subcls = '';
$cls = '';
@ -12,32 +12,6 @@ foreach($projects as $project):
$failure = null;
if (count($builds[$project->getId()])) {
// Use the latest build information to determine current status:
$latestBuild = $builds[$project->getId()][0];
switch ($latestBuild->getStatus()) {
case 0:
$cls = 'active';
$status = 'Pending';
break;
case 1:
$cls = 'warning';
$status = 'Running';
break;
case 2:
$cls = 'success';
$status = 'Success';
break;
case 3:
$cls = 'danger';
$status = 'Failed';
break;
}
// Use the last 5 builds to determine project health:
$successes = 0;
$failures = 0;
@ -65,13 +39,10 @@ foreach($projects as $project):
}
if ($failures == 0) {
$health = 'Good';
$subcls = 'green';
} elseif ($successes == 0) {
$health = 'Bad';
$subcls = 'red';
} else {
$health = 'Warning';
$subcls = 'yellow';
}
@ -79,27 +50,27 @@ foreach($projects as $project):
$buildCount = count($builds[$project->getId()]);
$lastSuccess = $successful[$project->getId()];
$lastFailure = $failed[$project->getId()];
$message = 'No builds yet!';
$shortMessage = 'No builds yet!';
$message = Lang::get('no_builds_yet');
$shortMessage = Lang::get('no_builds_yet');
if ($buildCount > 0) {
if ($failures > 0) {
$shortMessage = $failures . ' / ' . $buildCount . ' failed.';
$message = $failures . ' out of the last ' . $buildCount . ' builds failed.';
$shortMessage = Lang::get('x_of_x_failed_short', $failures, $buildCount);
$message = Lang::get('x_of_x_failed', $failures, $buildCount);
if (!is_null($lastSuccess) && !is_null($lastSuccess->getFinished())) {
$message .= ' The last successful build was ' . $lastSuccess->getFinished()->format('M j Y') . '.';
$message .= Lang::get('last_successful_build', $lastSuccess->getFinished()->format('M j Y'));
} else {
$message .= ' This project has never built successfully.';
$message .= Lang::get('never_built_successfully');
}
} else {
$shortMessage = $buildCount . ' / ' . $buildCount . ' passed.';
$message = 'All of the last ' . $buildCount . ' builds passed.';
$message = Lang::get('all_builds_passed', $buildCount);
$shortMessage = Lang::get('all_builds_passed_short', $buildCount, $buildCount);
if (!is_null($lastFailure) && !is_null($lastFailure->getFinished())) {
$message .= ' The last failed build was ' . $lastFailure->getFinished()->format('M j Y') . '.';
$message .= Lang::get('last_failed_build', $lastFailure->getFinished()->format('M j Y'));
} else {
$message .= ' This project has never failed to build.';
$message .= Lang::get('never_failed_build');
}
}
}
@ -140,7 +111,7 @@ foreach($projects as $project):
<i class="fa fa-<?php print $project->getIcon(); ?>"></i>
</div>
<a href="<?php print PHPCI_URL; ?>project/view/<?php print $project->getId(); ?>" class="small-box-footer">
View Project <i class="fa fa-arrow-circle-right"></i>
<?php Lang::out('view_project'); ?> <i class="fa fa-arrow-circle-right"></i>
</a>
</div>

View file

@ -19,6 +19,11 @@ use PHPCI\Helper\Lang;
<!-- Theme style -->
<link href="<?php print PHPCI_URL; ?>assets/css/AdminLTE.css" rel="stylesheet" type="text/css" />
<script>
var PHPCI_URL = '<?php print PHPCI_URL; ?>';
var PHPCI_STRINGS = <?php print json_encode(Lang::getStrings()); ?>;
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.js"></script>
<script src="<?php print PHPCI_URL; ?>assets/js/class.js"></script>
<script src="<?php print PHPCI_URL; ?>assets/js/sprintf.js"></script>
@ -30,11 +35,6 @@ use PHPCI\Helper\Lang;
<script src="//cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<script>
var PHPCI_URL = '<?php print PHPCI_URL; ?>';
var PHPCI_STRINGS = <?php print json_encode(Lang::getStrings()); ?>;
</script>
<style>
.skin-blue .logo, .skin-blue .logo:hover {
background-image: url('/assets/img/logo-large.png');
@ -94,7 +94,7 @@ use PHPCI\Helper\Lang;
<nav class="navbar navbar-static-top" role="navigation">
<!-- Sidebar toggle button-->
<a href="#" class="navbar-btn sidebar-toggle" data-toggle="offcanvas" role="button">
<span class="sr-only"><?php print Lang::get('toggle_navigation'); ?></span>
<span class="sr-only"><?php Lang::out('toggle_navigation'); ?></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
@ -108,7 +108,7 @@ use PHPCI\Helper\Lang;
<span class="label label-info phpci-pending-count"></span>
</a>
<ul class="dropdown-menu">
<li class="header"><span class="phpci-pending-count"></span> builds pending</li>
<li class="header"><?php Lang::out('n_builds_pending', 0); ?></li>
<li>
<ul class="menu phpci-pending-list">
</ul>
@ -122,7 +122,7 @@ use PHPCI\Helper\Lang;
<span class="label label-warning phpci-running-count"></span>
</a>
<ul class="dropdown-menu">
<li class="header"><span class="phpci-running-count"></span> builds running</li>
<li class="header"><?php Lang::out('n_builds_running', 0); ?></li>
<li>
<ul class="menu phpci-running-list">
</ul>
@ -149,10 +149,10 @@ use PHPCI\Helper\Lang;
<!-- Menu Footer-->
<li class="user-footer">
<div class="pull-left">
<a href="<?php print PHPCI_URL ?>user/profile" class="btn btn-default btn-flat">Edit Profile</a>
<a href="<?php print PHPCI_URL ?>user/profile" class="btn btn-default btn-flat"><?php Lang::out('edit_profile'); ?></a>
</div>
<div class="pull-right">
<a href="<?php print PHPCI_URL ?>session/logout" class="btn btn-default btn-flat">Sign out</a>
<a href="<?php print PHPCI_URL ?>session/logout" class="btn btn-default btn-flat"><?php Lang::out('sign_out'); ?></a>
</div>
</li>
</ul>
@ -172,9 +172,7 @@ use PHPCI\Helper\Lang;
<img src="https://www.gravatar.com/avatar/<?php print md5($this->User()->getEmail()); ?>?d=mm" class="img-circle" alt="<?php print $this->User()->getName(); ?>" />
</div>
<div class="pull-left info">
<p>Hello, <?php print $this->User()->getName(); ?></p>
<a href="#"><i class="fa fa-circle text-success"></i> Online</a>
<p><?php Lang::out('hello_name', $this->User()->getName()); ?></p>
</div>
</div>
@ -182,7 +180,7 @@ use PHPCI\Helper\Lang;
<ul class="sidebar-menu">
<li class="active">
<a href="<?php print PHPCI_URL; ?>">
<i class="fa fa-dashboard"></i> <span>Dashboard</span>
<i class="fa fa-dashboard"></i> <span><?php Lang::out('dashboard'); ?></span>
</a>
</li>
@ -190,32 +188,32 @@ use PHPCI\Helper\Lang;
<li class="treeview">
<a href="#">
<i class="fa fa-edit"></i>
<span>Admin Options</span>
<span><?php Lang::out('admin_options'); ?></span>
<i class="fa fa-angle-left pull-right"></i>
</a>
<ul class="treeview-menu">
<li>
<a href="<?php print PHPCI_URL; ?>project/add">
<i class="fa fa-angle-double-right"></i> Add Project
<i class="fa fa-angle-double-right"></i> <?php Lang::out('add_project'); ?>
</a>
</li>
<li>
<a href="<?php print PHPCI_URL; ?>settings">
<i class="fa fa-angle-double-right"></i> Settings
<i class="fa fa-angle-double-right"></i> <?php Lang::out('settings'); ?>
</a>
</li>
<li>
<a href="<?php print PHPCI_URL; ?>user">
<i class="fa fa-angle-double-right"></i> Manage Users
<i class="fa fa-angle-double-right"></i> <?php Lang::out('manage_users'); ?>
</a>
</li>
<li>
<a href="<?php print PHPCI_URL; ?>plugin">
<i class="fa fa-angle-double-right"></i> Plugins
<i class="fa fa-angle-double-right"></i> <?php Lang::out('plugins'); ?>
</a>
</li>
</ul>
@ -233,26 +231,26 @@ use PHPCI\Helper\Lang;
<ul class="treeview-menu">
<li>
<a href="<?php print PHPCI_URL; ?>project/view/<?php print $project->getId(); ?>">
<i class="fa fa-angle-double-right"></i> View
<i class="fa fa-angle-double-right"></i> <?php Lang::out('view'); ?>
</a>
</li>
<li>
<a href="<?php print PHPCI_URL; ?>project/build/<?php print $project->getId(); ?>">
<i class="fa fa-angle-double-right"></i> Build Now
<i class="fa fa-angle-double-right"></i> <?php Lang::out('build_now'); ?>
</a>
</li>
<?php if ($this->User()->getIsAdmin()): ?>
<li>
<a href="<?php print PHPCI_URL; ?>project/edit/<?php print $project->getId(); ?>">
<i class="fa fa-angle-double-right"></i> Edit Project
<i class="fa fa-angle-double-right"></i> <?php Lang::out('edit_project'); ?>
</a>
</li>
<li>
<a href="<?php print PHPCI_URL; ?>project/delete/<?php print $project->getId(); ?>">
<i class="fa fa-angle-double-right"></i> Delete Project
<i class="fa fa-angle-double-right"></i> <?php Lang::out('delete_project'); ?>
</a>
</li>
<?php endif; ?>

View file

@ -51,7 +51,7 @@ var PHPCI = {
$('.phpci-pending').hide();
} else {
$('.phpci-pending').show();
$('.phpci-pending-count').text(data.pending.count);
$('.phpci-pending .header').text(Lang.get('n_builds_pending', data.pending.count));
$.each(data.pending.items, function (idx, build) {
$('.phpci-pending-list').append(build.header_row);
@ -62,7 +62,7 @@ var PHPCI = {
$('.phpci-running').hide();
} else {
$('.phpci-running').show();
$('.phpci-running-count').text(data.running.count);
$('.phpci-running .header').text(Lang.get('n_builds_running', data.running.count));
$.each(data.running.items, function (idx, build) {
$('.phpci-running-list').append(build.header_row);
@ -471,4 +471,19 @@ function dateFormat(date)
rtn += ' ' + date.getHours() + ':' + date.getMinutes();
return rtn;
}
}
var Lang = {
get: function () {
var args = Array.prototype.slice.call(arguments);;
var string = args.shift();
if (PHPCI_STRINGS[string]) {
args.unshift(PHPCI_STRINGS[string]);
return sprintf.apply(sprintf[0], args);
}
return '';
}
};