i18n.php

Go to the documentation of this file.
00001 <?php
00002 /* SVN FILE: $Id: cake_2console_2libs_2i18n_8php-source.html 580 2008-07-01 14:45:49Z gwoo $ */
00003 /**
00004  * Short description for file.
00005  *
00006  * Long description for file
00007  *
00008  * PHP versions 4 and 5
00009  *
00010  * CakePHP(tm) :  Rapid Development Framework <http://www.cakephp.org/>
00011  * Copyright 2005-2008, Cake Software Foundation, Inc.
00012  *                            1785 E. Sahara Avenue, Suite 490-204
00013  *                            Las Vegas, Nevada 89104
00014  *
00015  * Licensed under The MIT License
00016  * Redistributions of files must retain the above copyright notice.
00017  *
00018  * @filesource
00019  * @copyright      Copyright 2005-2008, Cake Software Foundation, Inc.
00020  * @link                http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
00021  * @package      cake
00022  * @subpackage    cake.cake.console.libs
00023  * @since          CakePHP(tm) v 1.2.0.5669
00024  * @version      $Revision: 580 $
00025  * @modifiedby    $LastChangedBy: gwoo $
00026  * @lastmodified    $Date: 2008-07-01 09:45:49 -0500 (Tue, 01 Jul 2008) $
00027  * @license      http://www.opensource.org/licenses/mit-license.php The MIT License
00028  */
00029 /**
00030  * Shell for I18N management.
00031  *
00032  * @package     cake
00033  * @subpackage  cake.cake.console.libs
00034  */
00035 class I18nShell extends Shell {
00036 /**
00037  * Contains database source to use
00038  *
00039  * @var string
00040  * @access public
00041  */
00042     var $dataSource = 'default';
00043 /**
00044  * Contains tasks to load and instantiate
00045  *
00046  * @var array
00047  * @access public
00048  */
00049     var $tasks = array('DbConfig', 'Extract');
00050 
00051 /**
00052  * Override startup of the Shell
00053  *
00054  * @access public
00055  */
00056     function startup() {
00057         $this->_welcome();
00058         if (isset($this->params['datasource'])) {
00059             $this->dataSource = $this->params['datasource'];
00060         }
00061 
00062         if ($this->command && !in_array($this->command, array('help'))) {
00063             if (!config('database')) {
00064                 $this->out(__('Your database configuration was not found. Take a moment to create one.', true), true);
00065                 return $this->DbConfig->execute();
00066             }
00067         }
00068     }
00069 /**
00070  * Override main() for help message hook
00071  *
00072  * @access public
00073  */
00074     function main() {
00075         $this->out(__('I18n Shell', true));
00076         $this->hr();
00077         $this->out(__('[E]xtract POT file from sources', true));
00078         $this->out(__('[I]nitialize i18n database table', true));
00079         $this->out(__('[H]elp', true));
00080         $this->out(__('[Q]uit', true));
00081 
00082         $choice = strtoupper($this->in(__('What would you like to do?', true), array('E', 'I', 'H', 'Q')));
00083         switch($choice) {
00084             case 'E':
00085                 $this->Extract->execute();
00086             break;
00087             case 'I':
00088                 $this->initdb();
00089             break;
00090             case 'H':
00091                 $this->help();
00092             break;
00093             case 'Q':
00094                 exit(0);
00095             break;
00096             default:
00097                 $this->out(__('You have made an invalid selection. Please choose a command to execute by entering E, I, H, or Q.', true));
00098         }
00099         $this->hr();
00100         $this->main();
00101     }
00102 /**
00103  * Initialize I18N database.
00104  *
00105  * @access public
00106  */
00107     function initdb() {
00108         $this->Dispatch->args = array('schema', 'run', 'create', 'i18n');
00109         $this->Dispatch->dispatch();
00110     }
00111 /**
00112  * Show help screen.
00113  *
00114  * @access public
00115  */
00116     function help() {
00117         $this->hr();
00118         $this->out(__('I18n Shell:', true));
00119         $this->hr();
00120         $this->out(__('I18n Shell initializes i18n database table for your application', true));
00121         $this->out(__('and generates .pot file(s) with translations.', true));
00122         $this->hr();
00123         $this->out(__('usage:', true));
00124         $this->out('   cake i18n help');
00125         $this->out('   cake i18n initdb [-datasource custom]');
00126         $this->out('');
00127         $this->hr();
00128 
00129         $this->Extract->help();
00130     }
00131 }
00132 
00133 ?>