Skip to content

Commit 75b512e

Browse files
committed
support package look up for find command
1 parent be65c3b commit 75b512e

File tree

5 files changed

+50
-10
lines changed

5 files changed

+50
-10
lines changed

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ translation lines with ease. Taking care of a multilingual interface is not a he
66
<br>
77
<br>
88

9-
<img src="http://s30.postimg.org/ni241hhpd/ezgif_com_resize.gif">
9+
<img src="http://s15.postimg.org/3lfrbeg7t/langman_2.gif">
1010
<br>
1111
<a href="https://travis-ci.org/themsaid/laravel-langman"><img src="https://travis-ci.org/themsaid/laravel-langman.svg?branch=master" alt="Build Status"></a>
1212
<a href="https://styleci.io/repos/55088784"><img src="https://styleci.io/repos/55088784/shield?style=flat" alt="StyleCI"></a>
@@ -23,7 +23,7 @@ Begin by installing the package through Composer. Run the following command in y
2323
$ composer require themsaid/laravel-langman
2424
```
2525

26-
Once done, add the following in the providers array of `config/app.php`:
26+
Once done, add the following line in your providers array of `config/app.php`:
2727

2828
```php
2929
Themsaid\Langman\LangmanServiceProvider::class
@@ -65,6 +65,14 @@ Brings only the translation of the `name` key in all languages.
6565

6666
---
6767

68+
```
69+
php artisan langman:show users.name.first
70+
```
71+
72+
Brings the translation of a nested key.
73+
74+
---
75+
6876
```
6977
php artisan langman:show users.nam -c
7078
```
@@ -104,7 +112,7 @@ asking you to give a translation for each, and finally save the given values to
104112

105113
```
106114
php artisan langman:trans users.name
107-
php artisan langman:trans users.name.en
115+
php artisan langman:trans users.name->en
108116
```
109117

110118
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
@@ -130,5 +138,4 @@ If you want a web interface to manage your language files instead, I recommend [
130138
by [Barry vd. Heuvel](https://github.com/barryvdh).
131139

132140
## TODO
133-
- Support nested translation lines in `langman:trans`, `langman:sync`, `langman:remove`, `langman:missing`.
134141
- Support vendor language files.

src/Commands/FindCommand.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class FindCommand extends Command
1414
*
1515
* @var string
1616
*/
17-
protected $signature = 'langman:find {keyword}';
17+
protected $signature = 'langman:find {keyword} {--package : Vendor Package name to search within.}';
1818

1919
/**
2020
* The name and signature of the console command.
@@ -57,6 +57,10 @@ public function __construct(Manager $manager)
5757
*/
5858
public function handle()
5959
{
60+
if ($package = $this->option('package')) {
61+
$this->manager->setPathToVendorPackage($package);
62+
}
63+
6064
$this->files = $this->manager->files();
6165

6266
if (empty($this->files)) {

src/Manager.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,14 @@ public function files()
7373
});
7474
});
7575

76-
// Hide files from "vendor" directory for now
77-
$filesByFile = $filesByFile->filter(function ($value, $key) {
78-
return ! Str::contains($key, ':');
79-
});
76+
// If the path does not contain "vendor" then we're looking at the
77+
// main language files of the application, in this case we will
78+
// neglect all vendor files.
79+
if (! Str::contains($this->path, 'vendor')) {
80+
$filesByFile = $filesByFile->filter(function ($value, $key) {
81+
return ! Str::contains($key, ':');
82+
});
83+
}
8084

8185
return $filesByFile->toArray();
8286
}
@@ -290,4 +294,15 @@ public function collectFromViews()
290294

291295
return $output;
292296
}
297+
298+
/**
299+
* Sets the path to a vendor package translation files.
300+
*
301+
* @param string $packageName
302+
* @return void
303+
*/
304+
public function setPathToVendorPackage($packageName)
305+
{
306+
$this->path = $this->path.'/vendor/'.$packageName;
307+
}
293308
}

tests/FindCommandTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,19 @@ public function testCommandOutputForFileWithNestedKeys()
4343
$this->assertRegExp('/user\.missing\.not_found(?:.*)user not found(?:.*)sp/', $this->consoleOutput());
4444
$this->assertNotContains('jarl_borg', $this->consoleOutput());
4545
}
46+
47+
public function testCommandOutputForPackage()
48+
{
49+
$this->createTempFiles([
50+
'en' => ['user' => "<?php\n return ['weight' => 'weight'];", 'category' => ''],
51+
'nl' => ['user' => '', 'category' => ''],
52+
'vendor' => ['package' => ['en' => ['file' => "<?php\n return ['not_found' => 'file not found here'];"], 'sp' => ['file' => "<?php\n return ['not_found' => 'something'];"]]],
53+
]);
54+
55+
$this->artisan('langman:find', ['keyword' => 'not found', '--package' => 'package']);
56+
57+
$this->assertRegExp('/key(?:.*)en(?:.*)sp/', $this->consoleOutput());
58+
$this->assertRegExp('/package::file\.not_found(?:.*)file not found here(?:.*)something/', $this->consoleOutput());
59+
$this->assertNotContains('weight', $this->consoleOutput());
60+
}
4661
}

tests/TestCase.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public function createTempFiles($files = [])
4242

4343
foreach ($content as $subDir => $subContent) {
4444
mkdir(__DIR__.'/temp/vendor/'.$file.'/'.$subDir);
45-
4645
foreach ($subContent as $subFile => $subsubContent) {
4746
file_put_contents(__DIR__.'/temp/'.$dir.'/'.$file.'/'.$subDir.'/'.$subFile.'.php', $subsubContent);
4847
}

0 commit comments

Comments
 (0)