I18nShell.php 3.1 KB

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