I18nShell.php 3.1 KB

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