/
i18n.php
139 lines (128 loc) · 3.41 KB
/
i18n.php
1
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
/**
* Internationalization Management Shell
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package cake
* @subpackage cake.cake.console.libs
* @since CakePHP(tm) v 1.2.0.5669
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Shell for I18N management.
*
* @package cake
* @subpackage cake.cake.console.libs
*/
class I18nShell extends Shell {
/**
* Contains database source to use
*
* @var string
* @access public
*/
public $dataSource = 'default';
/**
* Contains tasks to load and instantiate
*
* @var array
* @access public
*/
public $tasks = array('DbConfig', 'Extract');
/**
* Override startup of the Shell
*
*/
public function startup() {
$this->_welcome();
if (isset($this->params['datasource'])) {
$this->dataSource = $this->params['datasource'];
}
if ($this->command && !in_array($this->command, array('help'))) {
if (!config('database')) {
$this->out(__('Your database configuration was not found. Take a moment to create one.'), true);
return $this->DbConfig->execute();
}
}
}
/**
* Override main() for help message hook
*
*/
public function main() {
$this->out(__('<info>I18n Shell</info>'));
$this->hr();
$this->out(__('[E]xtract POT file from sources'));
$this->out(__('[I]nitialize i18n database table'));
$this->out(__('[H]elp'));
$this->out(__('[Q]uit'));
$choice = strtolower($this->in(__('What would you like to do?'), array('E', 'I', 'H', 'Q')));
switch ($choice) {
case 'e':
$this->Extract->execute();
break;
case 'i':
$this->initdb();
break;
case 'h':
$this->out($this->OptionParser->help());
break;
case 'q':
exit(0);
break;
default:
$this->out(__('You have made an invalid selection. Please choose a command to execute by entering E, I, H, or Q.'));
}
$this->hr();
$this->main();
}
/**
* Initialize I18N database.
*
*/
public function initdb() {
$this->Dispatch->args = array('schema', 'create', 'i18n');
$this->Dispatch->dispatch();
}
/**
* Get and configure the Option parser
*
* @return ConsoleOptionParser
*/
public function getOptionParser() {
$parser = parent::getOptionParser();
return $parser->description(__('I18n Shell initializes i18n database table for your application and generates .pot files(s) with translations.'))
->addSubcommand('initdb', array('help' => __('Initialize the i18n table.')))
->addSubcommand('extract', array(
'help' => __('Extract the po translations from your application'),
'parser' => $this->Extract->getOptionParser()
));
}
/**
* Show help screen.
*
*/
public function help() {
$this->hr();
$this->out(__('I18n Shell:'));
$this->hr();
$this->out(__('I18n Shell initializes i18n database table for your application'));
$this->out(__('and generates .pot file(s) with translations.'));
$this->hr();
$this->out(__('usage:'));
$this->out(' cake i18n help');
$this->out(' cake i18n initdb [-datasource custom]');
$this->out();
$this->hr();
$this->Extract->help();
}
}