Skip to content

Commit 7746221

Browse files
committed
update readme
1 parent 3cf8337 commit 7746221

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ Brings the translation of a vendor package language file.
8181

8282
---
8383

84+
```
85+
php artisan langman:show users --lang=en,it
86+
```
87+
88+
Brings the translation of only the "en" and "it" languages.
89+
90+
---
91+
8492
```
8593
php artisan langman:show users.nam -c
8694
```
@@ -120,12 +128,12 @@ asking you to give a translation for each, and finally save the given values to
120128

121129
```
122130
php artisan langman:trans users.name
123-
php artisan langman:trans users.name->en
131+
php artisan langman:trans users.name.first
132+
php artisan langman:trans users.name --lang=en
124133
php artisan langman:trans package::users.name
125134
```
126135

127-
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
128-
for the given language's value.
136+
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.
129137

130138
This command will add a new key if not existing, and updates the key if it is already there.
131139

src/Commands/TransCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class TransCommand extends Command
1313
*
1414
* @var string
1515
*/
16-
protected $signature = 'langman:trans {key}';
16+
protected $signature = 'langman:trans {key} {--lang=}';
1717

1818
/**
1919
* The name and signature of the console command.
@@ -88,6 +88,8 @@ public function handle()
8888
return;
8989
}
9090

91+
$this->languageKey = $this->option('lang');
92+
9193
if (empty($this->files = $this->filesFromKey())) {
9294
return;
9395
}
@@ -103,11 +105,10 @@ public function handle()
103105
private function parseKey()
104106
{
105107
try {
106-
preg_match('/^([^\.]*)\.([^\:]*)(?:\:)?(.*)?/', $this->argument('key'), $matches);
108+
preg_match('/^([^\.]*)\.([^\:]*)/', $this->argument('key'), $matches);
107109

108110
$this->fileName = $matches[1];
109111
$this->key = $matches[2];
110-
$this->languageKey = $matches[3];
111112
} catch (\ErrorException $e) {
112113
if (! $this->key) {
113114
$this->error('Could not recognize the key you want to translate.');

tests/TransCommandTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function testCommandErrorOutputOnLanguageNotFound()
1818
{
1919
$this->createTempFiles(['en' => ['users' => '']]);
2020

21-
$this->artisan('langman:trans', ['key' => 'users.name:sd']);
21+
$this->artisan('langman:trans', ['key' => 'users.name', '--lang' => 'sd']);
2222

2323
$this->assertContains('Language (sd) could not be found!', $this->consoleOutput());
2424
}
@@ -155,7 +155,7 @@ public function testCommandAsksForValueForOnlyProvidedLanguage()
155155
$command->shouldReceive('ask')->once()->with('/users\.name:en/', null)->andReturn('name');
156156

157157
$this->app['artisan']->add($command);
158-
$this->artisan('langman:trans', ['key' => 'users.name:en']);
158+
$this->artisan('langman:trans', ['key' => 'users.name', '--lang' => 'en']);
159159

160160
$enFile = (array) include $this->app['config']['langman.path'].'/en/users.php';
161161
$this->assertEquals('name', $enFile['name']);
@@ -196,7 +196,7 @@ public function testCommandAsksForLanguageForNestedKeysAndWriteFile()
196196
$command->shouldReceive('ask')->once()->with('/users\.name\.first:en/', null)->andReturn('name');
197197

198198
$this->app['artisan']->add($command);
199-
$this->artisan('langman:trans', ['key' => 'users.name.first:en']);
199+
$this->artisan('langman:trans', ['key' => 'users.name.first', '--lang' => 'en']);
200200

201201
$enFile = (array) include $this->app['config']['langman.path'].'/en/users.php';
202202
$this->assertEquals(['first' => 'name'], $enFile['name']);

0 commit comments

Comments
 (0)