CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.8 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.8
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • CacheShell
  • CommandListShell
  • CompletionShell
  • I18nShell
  • OrmCacheShell
  • PluginShell
  • RoutesShell
  • SchemaCacheShell
  • ServerShell
  1: <?php
  2: /**
  3:  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4:  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5:  *
  6:  * Licensed under The MIT License
  7:  * For full copyright and license information, please see the LICENSE.txt
  8:  * Redistributions of files must retain the above copyright notice.
  9:  *
 10:  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 11:  * @link          https://cakephp.org CakePHP(tm) Project
 12:  * @since         1.2.0
 13:  * @license       https://opensource.org/licenses/mit-license.php MIT License
 14:  */
 15: namespace Cake\Shell;
 16: 
 17: use Cake\Console\Shell;
 18: use Cake\Core\App;
 19: use Cake\Core\Plugin;
 20: use Cake\Utility\Inflector;
 21: use DirectoryIterator;
 22: 
 23: /**
 24:  * Shell for I18N management.
 25:  *
 26:  * @property \Cake\Shell\Task\ExtractTask $Extract
 27:  */
 28: class I18nShell extends Shell
 29: {
 30:     /**
 31:      * Contains tasks to load and instantiate
 32:      *
 33:      * @var array
 34:      */
 35:     public $tasks = ['Extract'];
 36: 
 37:     /**
 38:      * @var string[]
 39:      */
 40:     protected $_paths;
 41: 
 42:     /**
 43:      * Override main() for help message hook
 44:      *
 45:      * @return void
 46:      * @throws \InvalidArgumentException
 47:      * @throws \Cake\Core\Exception\MissingPluginException
 48:      * @throws \Cake\Console\Exception\StopException
 49:      */
 50:     public function main()
 51:     {
 52:         $this->out('<info>I18n Shell</info>');
 53:         $this->hr();
 54:         $this->out('[E]xtract POT file from sources');
 55:         $this->out('[I]nitialize a language from POT file');
 56:         $this->out('[H]elp');
 57:         $this->out('[Q]uit');
 58: 
 59:         $choice = strtolower($this->in('What would you like to do?', ['E', 'I', 'H', 'Q']));
 60:         switch ($choice) {
 61:             case 'e':
 62:                 $this->Extract->main();
 63:                 break;
 64:             case 'i':
 65:                 $this->init();
 66:                 break;
 67:             case 'h':
 68:                 $this->out($this->OptionParser->help());
 69:                 break;
 70:             case 'q':
 71:                 $this->_stop();
 72: 
 73:                 return;
 74:             default:
 75:                 $this->out('You have made an invalid selection. Please choose a command to execute by entering E, I, H, or Q.');
 76:         }
 77:         $this->hr();
 78:         $this->main();
 79:     }
 80: 
 81:     /**
 82:      * Inits PO file from POT file.
 83:      *
 84:      * @param string|null $language Language code to use.
 85:      * @return void
 86:      * @throws \Cake\Console\Exception\StopException
 87:      */
 88:     public function init($language = null)
 89:     {
 90:         if (!$language) {
 91:             $language = $this->in('Please specify language code, e.g. `en`, `eng`, `en_US` etc.');
 92:         }
 93:         if (strlen($language) < 2) {
 94:             $this->abort('Invalid language code. Valid is `en`, `eng`, `en_US` etc.');
 95:         }
 96: 
 97:         $this->_paths = App::path('Locale');
 98:         if ($this->param('plugin')) {
 99:             $plugin = Inflector::camelize($this->param('plugin'));
100:             $this->_paths = App::path('Locale', $plugin);
101:         }
102: 
103:         $response = $this->in('What folder?', null, rtrim($this->_paths[0], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR);
104:         $sourceFolder = rtrim($response, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
105:         $targetFolder = $sourceFolder . $language . DIRECTORY_SEPARATOR;
106:         if (!is_dir($targetFolder)) {
107:             mkdir($targetFolder, 0775, true);
108:         }
109: 
110:         $count = 0;
111:         $iterator = new DirectoryIterator($sourceFolder);
112:         foreach ($iterator as $fileinfo) {
113:             if (!$fileinfo->isFile()) {
114:                 continue;
115:             }
116:             $filename = $fileinfo->getFilename();
117:             $newFilename = $fileinfo->getBasename('.pot');
118:             $newFilename .= '.po';
119: 
120:             $this->createFile($targetFolder . $newFilename, file_get_contents($sourceFolder . $filename));
121:             $count++;
122:         }
123: 
124:         $this->out('Generated ' . $count . ' PO files in ' . $targetFolder);
125:     }
126: 
127:     /**
128:      * Gets the option parser instance and configures it.
129:      *
130:      * @return \Cake\Console\ConsoleOptionParser
131:      * @throws \Cake\Console\Exception\ConsoleException
132:      */
133:     public function getOptionParser()
134:     {
135:         $parser = parent::getOptionParser();
136:         $initParser = [
137:             'options' => [
138:                 'plugin' => [
139:                     'help' => 'Plugin name.',
140:                     'short' => 'p'
141:                 ],
142:                 'force' => [
143:                     'help' => 'Force overwriting.',
144:                     'short' => 'f',
145:                     'boolean' => true
146:                 ]
147:             ],
148:             'arguments' => [
149:                 'language' => [
150:                     'help' => 'Two-letter language code.'
151:                 ]
152:             ]
153:         ];
154: 
155:         $parser->setDescription(
156:             'I18n Shell generates .pot files(s) with translations.'
157:         )->addSubcommand('extract', [
158:             'help' => 'Extract the po translations from your application',
159:             'parser' => $this->Extract->getOptionParser()
160:         ])
161:         ->addSubcommand('init', [
162:             'help' => 'Init PO language file from POT file',
163:             'parser' => $initParser
164:         ]);
165: 
166:         return $parser;
167:     }
168: }
169: 
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs