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.7 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.7
      • 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:     /**
 32:      * Contains tasks to load and instantiate
 33:      *
 34:      * @var array
 35:      */
 36:     public $tasks = ['Extract'];
 37: 
 38:     /**
 39:      * @var string[]
 40:      */
 41:     protected $_paths;
 42: 
 43:     /**
 44:      * Override main() for help message hook
 45:      *
 46:      * @return void
 47:      * @throws \InvalidArgumentException
 48:      * @throws \Cake\Core\Exception\MissingPluginException
 49:      * @throws \Cake\Console\Exception\StopException
 50:      */
 51:     public function main()
 52:     {
 53:         $this->out('<info>I18n Shell</info>');
 54:         $this->hr();
 55:         $this->out('[E]xtract POT file from sources');
 56:         $this->out('[I]nitialize a language from POT file');
 57:         $this->out('[H]elp');
 58:         $this->out('[Q]uit');
 59: 
 60:         $choice = strtolower($this->in('What would you like to do?', ['E', 'I', 'H', 'Q']));
 61:         switch ($choice) {
 62:             case 'e':
 63:                 $this->Extract->main();
 64:                 break;
 65:             case 'i':
 66:                 $this->init();
 67:                 break;
 68:             case 'h':
 69:                 $this->out($this->OptionParser->help());
 70:                 break;
 71:             case 'q':
 72:                 $this->_stop();
 73: 
 74:                 return;
 75:             default:
 76:                 $this->out('You have made an invalid selection. Please choose a command to execute by entering E, I, H, or Q.');
 77:         }
 78:         $this->hr();
 79:         $this->main();
 80:     }
 81: 
 82:     /**
 83:      * Inits PO file from POT file.
 84:      *
 85:      * @param string|null $language Language code to use.
 86:      * @return void
 87:      * @throws \Cake\Console\Exception\StopException
 88:      */
 89:     public function init($language = null)
 90:     {
 91:         if (!$language) {
 92:             $language = $this->in('Please specify language code, e.g. `en`, `eng`, `en_US` etc.');
 93:         }
 94:         if (strlen($language) < 2) {
 95:             $this->abort('Invalid language code. Valid is `en`, `eng`, `en_US` etc.');
 96:         }
 97: 
 98:         $this->_paths = App::path('Locale');
 99:         if ($this->param('plugin')) {
100:             $plugin = Inflector::camelize($this->param('plugin'));
101:             $this->_paths = App::path('Locale', $plugin);
102:         }
103: 
104:         $response = $this->in('What folder?', null, rtrim($this->_paths[0], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR);
105:         $sourceFolder = rtrim($response, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
106:         $targetFolder = $sourceFolder . $language . DIRECTORY_SEPARATOR;
107:         if (!is_dir($targetFolder)) {
108:             mkdir($targetFolder, 0775, true);
109:         }
110: 
111:         $count = 0;
112:         $iterator = new DirectoryIterator($sourceFolder);
113:         foreach ($iterator as $fileinfo) {
114:             if (!$fileinfo->isFile()) {
115:                 continue;
116:             }
117:             $filename = $fileinfo->getFilename();
118:             $newFilename = $fileinfo->getBasename('.pot');
119:             $newFilename .= '.po';
120: 
121:             $this->createFile($targetFolder . $newFilename, file_get_contents($sourceFolder . $filename));
122:             $count++;
123:         }
124: 
125:         $this->out('Generated ' . $count . ' PO files in ' . $targetFolder);
126:     }
127: 
128:     /**
129:      * Gets the option parser instance and configures it.
130:      *
131:      * @return \Cake\Console\ConsoleOptionParser
132:      * @throws \Cake\Console\Exception\ConsoleException
133:      */
134:     public function getOptionParser()
135:     {
136:         $parser = parent::getOptionParser();
137:         $initParser = [
138:             'options' => [
139:                 'plugin' => [
140:                     'help' => 'Plugin name.',
141:                     'short' => 'p'
142:                 ],
143:                 'force' => [
144:                     'help' => 'Force overwriting.',
145:                     'short' => 'f',
146:                     'boolean' => true
147:                 ]
148:             ],
149:             'arguments' => [
150:                 'language' => [
151:                     'help' => 'Two-letter language code.'
152:                 ]
153:             ]
154:         ];
155: 
156:         $parser->setDescription(
157:             'I18n Shell generates .pot files(s) with translations.'
158:         )->addSubcommand('extract', [
159:             'help' => 'Extract the po translations from your application',
160:             'parser' => $this->Extract->getOptionParser()
161:         ])
162:         ->addSubcommand('init', [
163:             'help' => 'Init PO language file from POT file',
164:             'parser' => $initParser
165:         ]);
166: 
167:         return $parser;
168:     }
169: }
170: 
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