diff --git a/PHPCI/Controller/HomeController.php b/PHPCI/Controller/HomeController.php index 0bb176dc..5d9678a7 100644 --- a/PHPCI/Controller/HomeController.php +++ b/PHPCI/Controller/HomeController.php @@ -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')); diff --git a/PHPCI/Helper/Lang.php b/PHPCI/Helper/Lang.php index 44017ae6..dc612513 100644 --- a/PHPCI/Helper/Lang.php +++ b/PHPCI/Helper/Lang.php @@ -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() diff --git a/PHPCI/Languages/lang.en-gb.php b/PHPCI/Languages/lang.en-gb.php new file mode 100644 index 00000000..0eaeb261 --- /dev/null +++ b/PHPCI/Languages/lang.en-gb.php @@ -0,0 +1,52 @@ + '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', +); \ No newline at end of file diff --git a/PHPCI/Languages/lang.en.php b/PHPCI/Languages/lang.en-us.php similarity index 58% rename from PHPCI/Languages/lang.en.php rename to PHPCI/Languages/lang.en-us.php index 4dc96d09..e0d5d78f 100644 --- a/PHPCI/Languages/lang.en.php +++ b/PHPCI/Languages/lang.en-us.php @@ -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', -); \ No newline at end of file +require_once(dirname(__FILE__) . '/lang.en-gb.php'); \ No newline at end of file diff --git a/PHPCI/View/Home/index.phtml b/PHPCI/View/Home/index.phtml index db351c2e..cf837b07 100644 --- a/PHPCI/View/Home/index.phtml +++ b/PHPCI/View/Home/index.phtml @@ -1,3 +1,4 @@ +
@@ -7,7 +8,7 @@
-

Latest Builds

+

@@ -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 @@
  • - format('g:ia'); ?> + format('H:i'); ?>

    getProject()->getTitle(); ?> diff --git a/PHPCI/View/SummaryTable.phtml b/PHPCI/View/SummaryTable.phtml index 438f78b6..d8ee8a56 100644 --- a/PHPCI/View/SummaryTable.phtml +++ b/PHPCI/View/SummaryTable.phtml @@ -1,10 +1,10 @@ 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):

    - View Project +
  • diff --git a/PHPCI/View/layout.phtml b/PHPCI/View/layout.phtml index f2bd6b2e..4728468d 100644 --- a/PHPCI/View/layout.phtml +++ b/PHPCI/View/layout.phtml @@ -19,6 +19,11 @@ use PHPCI\Helper\Lang; + + @@ -30,11 +35,6 @@ use PHPCI\Helper\Lang; - -