2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2010-05-29 15:20:28 +00:00
|
|
|
* Internationalization Management Shell
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:38:58 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-11-06 06:46:59 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2010-01-26 19:18:20 +00:00
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2010-01-26 19:18:20 +00:00
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-11-06 06:00:11 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2010-12-24 19:26:26 +00:00
|
|
|
* @package cake.console.shells
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.5669
|
2009-11-06 06:51:51 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Shell for I18N management.
|
|
|
|
*
|
2010-12-24 19:26:26 +00:00
|
|
|
* @package cake.console.shells
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class I18nShell extends Shell {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Contains database source to use
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $dataSource = 'default';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Contains tasks to load and instantiate
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $tasks = array('DbConfig', 'Extract');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Override startup of the Shell
|
|
|
|
*
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function startup() {
|
2008-06-03 05:11:04 +00:00
|
|
|
$this->_welcome();
|
2008-05-30 11:40:08 +00:00
|
|
|
if (isset($this->params['datasource'])) {
|
|
|
|
$this->dataSource = $this->params['datasource'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->command && !in_array($this->command, array('help'))) {
|
|
|
|
if (!config('database')) {
|
2010-04-15 15:43:39 +00:00
|
|
|
$this->out(__('Your database configuration was not found. Take a moment to create one.'), true);
|
2008-05-30 11:40:08 +00:00
|
|
|
return $this->DbConfig->execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Override main() for help message hook
|
|
|
|
*
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function main() {
|
2010-10-10 04:59:45 +00:00
|
|
|
$this->out(__('<info>I18n Shell</info>'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->hr();
|
2010-04-15 15:43:39 +00:00
|
|
|
$this->out(__('[E]xtract POT file from sources'));
|
|
|
|
$this->out(__('[I]nitialize i18n database table'));
|
|
|
|
$this->out(__('[H]elp'));
|
|
|
|
$this->out(__('[Q]uit'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-04-15 15:43:39 +00:00
|
|
|
$choice = strtolower($this->in(__('What would you like to do?'), array('E', 'I', 'H', 'Q')));
|
2008-10-23 00:10:44 +00:00
|
|
|
switch ($choice) {
|
2009-08-10 23:47:41 +00:00
|
|
|
case 'e':
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Extract->execute();
|
|
|
|
break;
|
2009-08-10 23:47:41 +00:00
|
|
|
case 'i':
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->initdb();
|
|
|
|
break;
|
2009-08-10 23:47:41 +00:00
|
|
|
case 'h':
|
2010-10-10 04:59:45 +00:00
|
|
|
$this->out($this->OptionParser->help());
|
2008-05-30 11:40:08 +00:00
|
|
|
break;
|
2009-08-10 23:47:41 +00:00
|
|
|
case 'q':
|
2008-05-30 11:40:08 +00:00
|
|
|
exit(0);
|
|
|
|
break;
|
|
|
|
default:
|
2010-04-15 15:43:39 +00:00
|
|
|
$this->out(__('You have made an invalid selection. Please choose a command to execute by entering E, I, H, or Q.'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
$this->hr();
|
|
|
|
$this->main();
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Initialize I18N database.
|
|
|
|
*
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function initdb() {
|
2010-10-16 05:38:11 +00:00
|
|
|
$this->dispatchShell('schema create i18n');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-10-10 04:59:45 +00:00
|
|
|
/**
|
|
|
|
* Get and configure the Option parser
|
|
|
|
*
|
|
|
|
* @return ConsoleOptionParser
|
|
|
|
*/
|
2010-10-10 05:56:23 +00:00
|
|
|
public function getOptionParser() {
|
|
|
|
$parser = parent::getOptionParser();
|
2010-10-14 01:08:53 +00:00
|
|
|
return $parser->description(
|
|
|
|
__('I18n Shell initializes i18n database table for your application and generates .pot files(s) with translations.')
|
|
|
|
)->addSubcommand('initdb', array(
|
2010-10-10 20:19:34 +00:00
|
|
|
'help' => __('Initialize the i18n table.')
|
2010-10-14 01:08:53 +00:00
|
|
|
))->addSubcommand('extract', array(
|
2010-10-10 05:56:23 +00:00
|
|
|
'help' => __('Extract the po translations from your application'),
|
|
|
|
'parser' => $this->Extract->getOptionParser()
|
|
|
|
));
|
2010-10-10 04:59:45 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|