From 7e3df7f426b585adbbf5dc7385ddd3b57c90d588 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Fri, 22 Oct 2010 16:26:35 +0200 Subject: [PATCH] Revert "Updated package.xml (includes locale files). Made translation optional." This reverts commit 5c3e6593a08a30e19b0c6f8812a8ad448666c074. --- framework/Cli/lib/Horde/Cli.php | 80 ++++-------- framework/Cli/package.xml | 278 ++-------------------------------------- 2 files changed, 31 insertions(+), 327 deletions(-) diff --git a/framework/Cli/lib/Horde/Cli.php b/framework/Cli/lib/Horde/Cli.php index d8f7bb146..74b3dfd10 100644 --- a/framework/Cli/lib/Horde/Cli.php +++ b/framework/Cli/lib/Horde/Cli.php @@ -14,13 +14,6 @@ class Horde_Cli { /** - * The location of the data directory which contains locale information. - * This contains @data_dir@ if the package has not been installed via - * PEAR. - */ - const LOCALE_DIR = '@data_dir@/locale'; - - /** * Are we running on a console? * * @var boolean @@ -135,9 +128,20 @@ class Horde_Cli /** * Detect the current environment (web server or console) and sets * internal values accordingly. + * + * The constructor must not be called after init(). + * + * @param Horde_Translation $dict A translation handler implementing + * Horde_Translation. */ - public function __construct() + public function __construct($dict = null) { + if ($dict) { + $this->_dict = $dict; + } else { + $this->_dict = new Horde_Translation_Gettext('Horde_Cli', dirname(__FILE__) . '/../../locale'); + } + $this->_console = $this->runningFromCLI(); if ($this->_console) { @@ -331,7 +335,7 @@ class Horde_Cli } $this->writeln($this->red('====================')); $this->writeln(); - $this->writeln($this->red($this->_t("Fatal Error:"))); + $this->writeln($this->red($this->_dict->t("Fatal Error:"))); $this->writeln($this->red($error)); $this->writeln(); $this->writeln((string)$backtrace); @@ -365,7 +369,7 @@ class Horde_Cli foreach ($choices as $key => $choice) { $this->writeln($this->indent('(' . $this->bold($key) . ') ' . $choice)); } - $this->writeln($this->_t("Type your choice: "), true); + $this->writeln($this->_dict->t("Type your choice: "), true); @ob_flush(); // Get the user choice. @@ -376,7 +380,7 @@ class Horde_Cli if (isset($choices[$response])) { return $response; } else { - $this->writeln($this->red(sprintf($this->_t("\"%s\" is not a valid choice."), $response))); + $this->writeln($this->red(sprintf($this->_dict->t("\"%s\" is not a valid choice."), $response))); } } else { @ob_flush(); @@ -446,18 +450,20 @@ class Horde_Cli * none. Also initialize a few variables in $_SERVER that aren't present * from the CLI. * - * @param Horde_Translation_Factory $t A translation factory that - * generates a Horde_Translation - * instance. + * You must not call init() statically before calling the constructor. + * Either use the singleton() method to retrieve a Horde_Cli object after + * calling init(), or don't call init() statically. + * + * @param Horde_Translation $dict A translation handler implementing + * Horde_Translation. * * @return Horde_Cli A Horde_Cli instance. */ - static public function init(Horde_Translation_Factory $t = null) + static public function init($dict = null) { /* Run constructor now because it requires $_SERVER['SERVER_NAME'] to * be empty if called with a CGI SAPI. */ - $cli = new self(); - $cli->initTranslation($t); + $cli = new self($dict); @set_time_limit(0); ob_implicit_flush(true); @@ -482,46 +488,6 @@ class Horde_Cli } /** - * Try to initialize the translation system. - * - * @param Horde_Translation_Factory $t A translation factory that - * generates a Horde_Translation - * instance. - * - * @return Horde_Cli A Horde_Cli instance. - */ - public function initTranslation(Horde_Translation_Factory $t = null) - { - if ($t === null && class_exists('Horde_Translation_Factory_Gettext')) { - $t = new Horde_Translation_Factory_Gettext(); - } - if ($t !== null) { - $this->_dict = $t->createTranslation('Horde_Cli', self::LOCALE_DIR, dirname(__FILE__) . '/../../locale'); - } else { - $this->_dict = false; - } - } - - /** - * Returns the translation of a message. - * - * @param string $message The string to translate. - * - * @return string The string translation, or the original string if no - * translation exists. - */ - private function _t($message) - { - if ($this->_dict === false) { - return $message; - } else if ($this->_dict === null) { - $this->initTranslation(); - return $this->_t($message); - } - return $this->_dict->t($message); - } - - /** * Make sure we're being called from the command line, and not via * the web. * diff --git a/framework/Cli/package.xml b/framework/Cli/package.xml index 28ccb029a..d323caef4 100644 --- a/framework/Cli/package.xml +++ b/framework/Cli/package.xml @@ -16,8 +16,8 @@ jan@horde.org yes - 2010-10-18 - + 2010-08-15 + 0.2.0 0.2.0 @@ -42,272 +42,9 @@ - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -322,13 +59,14 @@ Support pear.horde.org - - Translation pear.horde.org - + + gettext + + @@ -391,7 +129,7 @@ Add 'default' parameter to Horde_CLI::prompt(). beta beta - 2010-10-18 + 2010-08-15 LGPL * Horde_CLI:: -> Horde_Cli:: -- 2.11.0