I18nShell.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * Internationalization Management Shell
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * For full copyright and license information, please see the LICENSE.txt
  12. * Redistributions of files must retain the above copyright notice.
  13. *
  14. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  15. * @link http://cakephp.org CakePHP(tm) Project
  16. * @since CakePHP(tm) v 1.2.0.5669
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. App::uses('AppShell', 'Console/Command');
  20. /**
  21. * Shell for I18N management.
  22. *
  23. * @package Cake.Console.Command
  24. */
  25. class I18nShell extends AppShell {
  26. /**
  27. * Contains database source to use
  28. *
  29. * @var string
  30. */
  31. public $dataSource = 'default';
  32. /**
  33. * Contains tasks to load and instantiate
  34. *
  35. * @var array
  36. */
  37. public $tasks = array('DbConfig', 'Extract');
  38. /**
  39. * Override startup of the Shell
  40. *
  41. * @return mixed
  42. */
  43. public function startup() {
  44. $this->_welcome();
  45. if (isset($this->params['datasource'])) {
  46. $this->dataSource = $this->params['datasource'];
  47. }
  48. if ($this->command && !in_array($this->command, array('help'))) {
  49. if (!config('database')) {
  50. $this->out(__d('cake_console', 'Your database configuration was not found. Take a moment to create one.'), true);
  51. return $this->DbConfig->execute();
  52. }
  53. }
  54. }
  55. /**
  56. * Override main() for help message hook
  57. *
  58. * @return void
  59. */
  60. public function main() {
  61. $this->out(__d('cake_console', '<info>I18n Shell</info>'));
  62. $this->hr();
  63. $this->out(__d('cake_console', '[E]xtract POT file from sources'));
  64. $this->out(__d('cake_console', '[I]nitialize i18n database table'));
  65. $this->out(__d('cake_console', '[H]elp'));
  66. $this->out(__d('cake_console', '[Q]uit'));
  67. $choice = strtolower($this->in(__d('cake_console', 'What would you like to do?'), array('E', 'I', 'H', 'Q')));
  68. switch ($choice) {
  69. case 'e':
  70. $this->Extract->execute();
  71. break;
  72. case 'i':
  73. $this->initdb();
  74. break;
  75. case 'h':
  76. $this->out($this->OptionParser->help());
  77. break;
  78. case 'q':
  79. exit(0);
  80. break;
  81. default:
  82. $this->out(__d('cake_console', 'You have made an invalid selection. Please choose a command to execute by entering E, I, H, or Q.'));
  83. }
  84. $this->hr();
  85. $this->main();
  86. }
  87. /**
  88. * Initialize I18N database.
  89. *
  90. * @return void
  91. */
  92. public function initdb() {
  93. $this->dispatchShell('schema create i18n');
  94. }
  95. /**
  96. * Get and configure the Option parser
  97. *
  98. * @return ConsoleOptionParser
  99. */
  100. public function getOptionParser() {
  101. $parser = parent::getOptionParser();
  102. return $parser->description(
  103. __d('cake_console', 'I18n Shell initializes i18n database table for your application and generates .pot files(s) with translations.')
  104. )->addSubcommand('initdb', array(
  105. 'help' => __d('cake_console', 'Initialize the i18n table.')
  106. ))->addSubcommand('extract', array(
  107. 'help' => __d('cake_console', 'Extract the po translations from your application'),
  108. 'parser' => $this->Extract->getOptionParser()
  109. ));
  110. }
  111. }