1: <?php
  2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18: 
 19: 
 20: App::uses('AppShell', 'Console/Command');
 21: 
 22:  23:  24:  25:  26: 
 27: class I18nShell extends AppShell {
 28: 
 29:  30:  31:  32:  33: 
 34:     public $dataSource = 'default';
 35: 
 36:  37:  38:  39:  40: 
 41:     public $tasks = array('DbConfig', 'Extract');
 42: 
 43:  44:  45:  46:  47: 
 48:     public function startup() {
 49:         $this->_welcome();
 50:         if (isset($this->params['datasource'])) {
 51:             $this->dataSource = $this->params['datasource'];
 52:         }
 53: 
 54:         if ($this->command && !in_array($this->command, array('help'))) {
 55:             if (!config('database')) {
 56:                 $this->out(__d('cake_console', 'Your database configuration was not found. Take a moment to create one.'));
 57:                 return $this->DbConfig->execute();
 58:             }
 59:         }
 60:     }
 61: 
 62:  63:  64:  65:  66: 
 67:     public function main() {
 68:         $this->out(__d('cake_console', '<info>I18n Shell</info>'));
 69:         $this->hr();
 70:         $this->out(__d('cake_console', '[E]xtract POT file from sources'));
 71:         $this->out(__d('cake_console', '[I]nitialize i18n database table'));
 72:         $this->out(__d('cake_console', '[H]elp'));
 73:         $this->out(__d('cake_console', '[Q]uit'));
 74: 
 75:         $choice = strtolower($this->in(__d('cake_console', 'What would you like to do?'), array('E', 'I', 'H', 'Q')));
 76:         switch ($choice) {
 77:             case 'e':
 78:                 $this->Extract->execute();
 79:                 break;
 80:             case 'i':
 81:                 $this->initdb();
 82:                 break;
 83:             case 'h':
 84:                 $this->out($this->OptionParser->help());
 85:                 break;
 86:             case 'q':
 87:                 return $this->_stop();
 88:             default:
 89:                 $this->out(__d('cake_console', 'You have made an invalid selection. Please choose a command to execute by entering E, I, H, or Q.'));
 90:         }
 91:         $this->hr();
 92:         $this->main();
 93:     }
 94: 
 95:  96:  97:  98:  99: 
100:     public function initdb() {
101:         $this->dispatchShell('schema create i18n');
102:     }
103: 
104: 105: 106: 107: 108: 
109:     public function getOptionParser() {
110:         $parser = parent::getOptionParser();
111:         return $parser->description(
112:             __d('cake_console', 'I18n Shell initializes i18n database table for your application and generates .pot files(s) with translations.')
113:             )->addSubcommand('initdb', array(
114:                 'help' => __d('cake_console', 'Initialize the i18n table.')
115:             ))->addSubcommand('extract', array(
116:                 'help' => __d('cake_console', 'Extract the po translations from your application'),
117:                 'parser' => $this->Extract->getOptionParser()
118:             ));
119:     }
120: 
121: }
122: