diff --git a/README.md b/README.md index 088f08d..238846f 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,14 @@ Brings the translation of a vendor package language file. --- +``` +php artisan langman:show users --lang=en,it +``` + +Brings the translation of only the "en" and "it" languages. + +--- + ``` php artisan langman:show users.nam -c ``` @@ -120,12 +128,12 @@ asking you to give a translation for each, and finally save the given values to ``` php artisan langman:trans users.name -php artisan langman:trans users.name->en +php artisan langman:trans users.name.first +php artisan langman:trans users.name --lang=en php artisan langman:trans package::users.name ``` -In the first case it'll ask you to give a translation for the given key in all languages, in the second case it'll ask you only -for the given language's value. +Using this command you may set a language key (plain or nested) for a given group, you may also specify which language you wish to set leaving the other languages as is. This command will add a new key if not existing, and updates the key if it is already there. diff --git a/src/Commands/TransCommand.php b/src/Commands/TransCommand.php index 9036cfc..1368eb4 100644 --- a/src/Commands/TransCommand.php +++ b/src/Commands/TransCommand.php @@ -13,7 +13,7 @@ class TransCommand extends Command * * @var string */ - protected $signature = 'langman:trans {key}'; + protected $signature = 'langman:trans {key} {--lang=}'; /** * The name and signature of the console command. @@ -88,6 +88,8 @@ public function handle() return; } + $this->languageKey = $this->option('lang'); + if (empty($this->files = $this->filesFromKey())) { return; } @@ -103,11 +105,10 @@ public function handle() private function parseKey() { try { - preg_match('/^([^\.]*)\.([^\:]*)(?:\:)?(.*)?/', $this->argument('key'), $matches); + preg_match('/^([^\.]*)\.([^\:]*)/', $this->argument('key'), $matches); $this->fileName = $matches[1]; $this->key = $matches[2]; - $this->languageKey = $matches[3]; } catch (\ErrorException $e) { if (! $this->key) { $this->error('Could not recognize the key you want to translate.'); diff --git a/tests/TransCommandTest.php b/tests/TransCommandTest.php index 098d342..0704dfb 100644 --- a/tests/TransCommandTest.php +++ b/tests/TransCommandTest.php @@ -18,7 +18,7 @@ public function testCommandErrorOutputOnLanguageNotFound() { $this->createTempFiles(['en' => ['users' => '']]); - $this->artisan('langman:trans', ['key' => 'users.name:sd']); + $this->artisan('langman:trans', ['key' => 'users.name', '--lang' => 'sd']); $this->assertContains('Language (sd) could not be found!', $this->consoleOutput()); } @@ -155,7 +155,7 @@ public function testCommandAsksForValueForOnlyProvidedLanguage() $command->shouldReceive('ask')->once()->with('/users\.name:en/', null)->andReturn('name'); $this->app['artisan']->add($command); - $this->artisan('langman:trans', ['key' => 'users.name:en']); + $this->artisan('langman:trans', ['key' => 'users.name', '--lang' => 'en']); $enFile = (array) include $this->app['config']['langman.path'].'/en/users.php'; $this->assertEquals('name', $enFile['name']); @@ -196,7 +196,7 @@ public function testCommandAsksForLanguageForNestedKeysAndWriteFile() $command->shouldReceive('ask')->once()->with('/users\.name\.first:en/', null)->andReturn('name'); $this->app['artisan']->add($command); - $this->artisan('langman:trans', ['key' => 'users.name.first:en']); + $this->artisan('langman:trans', ['key' => 'users.name.first', '--lang' => 'en']); $enFile = (array) include $this->app['config']['langman.path'].'/en/users.php'; $this->assertEquals(['first' => 'name'], $enFile['name']);