/** * Returns the plural translation of a message. * * @param string $singular The singular version to translate. * @param string $plural The plural version to translate. * @param integer $number The number that determines singular vs. plural. * * @return string The string translation, or the original string if no * translation exists. */ public static function ngettext($singular, $plural, $number) { self::$_domain = 'Horde_Cli'; self::$_directory = '@data_dir@' == '@' . 'data_dir' . '@' ? __DIR__ . '/../../../locale' : '@data_dir@/Horde_Cli/locale'; return parent::ngettext($singular, $plural, $number); }
/** * Prompts for a user response. * * @todo Horde 5: switch $choices and $default * * @param string $prompt The message to display when prompting the user. * @param array $choices The choices available to the user or null for a * text input. * @param string $default The default value if no value specified. * * @return mixed The user's response to the prompt. */ public function prompt($prompt, $choices = null, $default = null) { // Main event loop to capture top level command. while (true) { // Print out the prompt message. if (is_array($choices) && !empty($choices)) { $this->writeln(wordwrap($prompt) . ' ', !is_array($choices)); foreach ($choices as $key => $choice) { $this->writeln($this->indent('(' . $this->bold($key) . ') ' . $choice)); } $question = Horde_Cli_Translation::t("Type your choice"); if ($default !== null) { $question .= ' [' . $default . ']'; } $this->writeln($question . ': ', true); @ob_flush(); // Get the user choice. $response = trim(fgets(STDIN)); if ($response === '' && $default !== null) { $response = $default; } if (isset($choices[$response])) { return $response; } else { $this->writeln($this->red(sprintf(Horde_Cli_Translation::t("\"%s\" is not a valid choice."), $response))); } } else { if ($default !== null) { $prompt .= ' [' . $default . ']'; } $this->writeln(wordwrap($prompt) . ' ', true); @ob_flush(); $response = trim(fgets(STDIN)); if ($response === '' && $default !== null) { $response = $default; } return $response; } } return true; }