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