Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
themsaid committed Apr 9, 2016
1 parent 3cf8337 commit 7746221
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down Expand Up @@ -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.

Expand Down
7 changes: 4 additions & 3 deletions src/Commands/TransCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -88,6 +88,8 @@ public function handle()
return;
}

$this->languageKey = $this->option('lang');

if (empty($this->files = $this->filesFromKey())) {
return;
}
Expand All @@ -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.');
Expand Down
6 changes: 3 additions & 3 deletions tests/TransCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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']);
Expand Down Expand Up @@ -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']);
Expand Down

0 comments on commit 7746221

Please sign in to comment.