diff --git a/Console/Command/TransifexShell.php b/Console/Command/TransifexShell.php index 3876a48..79d1544 100644 --- a/Console/Command/TransifexShell.php +++ b/Console/Command/TransifexShell.php @@ -18,7 +18,9 @@ class TransifexShell extends AppShell { public function startup() { parent::startup(); - $settings = array(); + $settings = array( + 'debug' => $this->params['debug'] + ); if (!empty($this->params['project'])) { $settings['project'] = $this->params['project']; } @@ -57,6 +59,34 @@ public function languages() { } } + /** + * TransifexShell::languages() + * + * @return void + */ + public function language() { + $lang = !empty($this->args[0]) ? $this->args[0] : null; + if (!$lang) { + return $this->error('No language specified, please use two-letter-code, e.g. "de" or "en".'); + } + $language = $this->Transifex->getLanguage($lang); + $this->out(print_r($language, true)); + } + + /** + * TransifexShell::languages() + * + * @return void + */ + public function language_info() { + $lang = !empty($this->args[0]) ? $this->args[0] : null; + if (!$lang) { + return $this->error('No language specified, please use two-letter-code, e.g. "de" or "en".'); + } + $language = $this->Transifex->getLanguageInfo($lang); + $this->out(print_r($language, true)); + } + /** * TransifexShell::statistics() * @@ -376,6 +406,10 @@ public function getOptionParser() { 'help' => 'Project', 'default' => '', ), + 'debug' => array( + 'help' => 'Debug output (for network/connection details).', + 'boolean' => true + ), ) ); $subcommandParserPull = $subcommandParser; @@ -410,28 +444,36 @@ public function getOptionParser() { return parent::getOptionParser() ->description("The Convert Shell converts files from dos/unix/mac to another system") ->addSubcommand('resources', array( - 'help' => 'List all resources', + 'help' => 'List all resources.', 'parser' => $subcommandParser )) ->addSubcommand('languages', array( - 'help' => 'List all languages', + 'help' => 'List all languages.', + 'parser' => $subcommandParser + )) + ->addSubcommand('language', array( + 'help' => 'Get project infos to a specific language.', 'parser' => $subcommandParser )) ->addSubcommand('statistics', array( - 'help' => 'Display project statistics', + 'help' => 'Display project statistics.', 'parser' => $subcommandParser )) ->addSubcommand('pull', array( - 'help' => 'Pull PO files', + 'help' => 'Pull PO files.', 'parser' => $subcommandParserPull )) ->addSubcommand('push', array( - 'help' => 'Push PO files', + 'help' => 'Push PO files.', 'parser' => $subcommandParserPull )) ->addSubcommand('update', array( - 'help' => 'Update POT files', + 'help' => 'Update POT files.', 'parser' => $subcommandParserPull + )) + ->addSubcommand('language_info', array( + 'help' => 'Get infos to a specific language.', + 'parser' => $subcommandParser )); } diff --git a/Lib/TransifexLib.php b/Lib/TransifexLib.php index fa28c76..aedb492 100644 --- a/Lib/TransifexLib.php +++ b/Lib/TransifexLib.php @@ -17,7 +17,7 @@ class TransifexLib { 'project' => '', 'user' => '', 'password' => '', - 'debug' => false, + 'debug' => false, // Verbose debugging for curl (when putting) ); /** @@ -94,6 +94,16 @@ public function getLanguage($language) { return $this->_get($url); } + /** + * TransifexLib::getLanguageInfo() + * + * @return array + */ + public function getLanguageInfo($language) { + $url = static::BASE_URL . 'language/' . $language . '/'; + return $this->_get($url); + } + /** * TransifexLib::getTranslations() * diff --git a/README.md b/README.md index 6fd065a..7521c98 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,8 @@ [![License](https://poser.pugx.org/dereuromark/cakephp-transifex/license.png)](https://packagist.org/packages/dereuromark/cakephp-transifex) [![Total Downloads](https://poser.pugx.org/dereuromark/cakephp-transifex/d/total.png)](https://packagist.org/packages/dereuromark/cakephp-transifex) -A CakePHP 2.x Plugin that works with Transifex and pulls/pushes translations. +A CakePHP 2.x Plugin that works with [Transifex](https://www.transifex.com/) and pulls/pushes translations. +It uses the [Transifex API v2](http://docs.transifex.com/developer/api/). Please note: New functionality has been tested against latest CakePHP v2.x only. Please upgrade if possible. @@ -68,6 +69,9 @@ If you happen to have one primary project and several other (plugin or CakePHP c Tip: If you want to dry-run it first, use `-d -v`. This will not modify your locale files but simulate the import. +### Debugging +Use `--debug` to have more verbose debugging output when pushing via cURL. + ## TODO * More tests diff --git a/Test/Case/Console/Command/TransifexShellTest.php b/Test/Case/Console/Command/TransifexShellTest.php index 335cdbf..49fd003 100644 --- a/Test/Case/Console/Command/TransifexShellTest.php +++ b/Test/Case/Console/Command/TransifexShellTest.php @@ -8,6 +8,10 @@ class TransifexShellTest extends CakeTestCase { public function setUp() { parent::setUp(); + CakePlugin::load(array( + 'Transifex' + )); + $this->TransifexShell = new TransifexShell(); } diff --git a/Test/Case/Lib/TransifexLibTest.php b/Test/Case/Lib/TransifexLibTest.php index fa70a56..769dca1 100644 --- a/Test/Case/Lib/TransifexLibTest.php +++ b/Test/Case/Lib/TransifexLibTest.php @@ -83,7 +83,7 @@ public function testPutTranslations() { 'strings_updated' => 0, 'strings_delete' => 0, ); - $file = 'C:\xampp\htdocs\repo\cakefest\Plugin\Transifex\Test\test_files\test.pot'; + $file = dirname(__FILE__) . '/../../test_files/test.pot'; $this->Transifex->expects($this->any()) ->method('_put') ->will($this->returnValue($mockedResponse));