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 @@ +