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