I18nShell.php 3.0 KB

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