Skip to content

Commit

Permalink
Fix laravel 9 - lang path changed (#8)
Browse files Browse the repository at this point in the history
* Update

* Fix styling

* Bump php

* Bump php

Co-authored-by: druc <druc@users.noreply.github.com>
  • Loading branch information
Constantin Druc and druc authored Apr 11, 2022
1 parent ae34ed5 commit 7e37aaa
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
fail-fast: true
matrix:
os: [ ubuntu-latest, windows-latest ]
php: [ 7.4, 8.0 ]
php: [ 8.0 ]
stability: [ prefer-lowest, prefer-stable ]

name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
}
],
"require": {
"php": "^7.4|^8.0",
"spatie/laravel-package-tools": "^1.4.3",
"illuminate/contracts": "^8.0|^9.0",
"php": "^8.0",
"spatie/laravel-package-tools": "^1.11.3",
"illuminate/contracts": "^9.0",
"ext-json": "*"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.3",
"orchestra/testbench": "^6.15",
"phpunit/phpunit": "^9.3"
"orchestra/testbench": "^7.02",
"phpunit/phpunit": "^9.5"
},
"autoload": {
"psr-4": {
Expand Down
1 change: 1 addition & 0 deletions config/langscanner.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

return [
'lang_dir_path' => base_path('lang'),
/*
|--------------------------------------------------------------------------
| Translation methods
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/LangscannerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function handle(Filesystem $filesystem): void
if ($this->argument('language')) {
$languages = new Languages([$this->argument('language')]);
} else {
$languages = Languages::fromPath(resource_path('lang'), $filesystem);
$languages = Languages::fromPath(config('langscanner.lang_dir_path'), $filesystem);
}

foreach ($languages->all() as $language) {
Expand Down
2 changes: 1 addition & 1 deletion src/FileTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct(array $opts)

$this->language = $opts['language'];
$this->disk = $opts['disk'] ?? resolve(Filesystem::class);
$this->rootPath = $opts['rootPath'] ?? resource_path('lang/');
$this->rootPath = $opts['rootPath'] ?? config('langscanner.lang_dir_path') . '/';
}

public function language(): string
Expand Down
5 changes: 4 additions & 1 deletion src/RequiredTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@ class RequiredTranslations
private array $translationMethods;
private array $excludedPaths;
private array $translations;
private string $langDirPath;

public function __construct(array $options, Filesystem $disk = null)
{
Assert::keyExists($options, 'paths');
Assert::keyExists($options, 'excluded_paths');
Assert::keyExists($options, 'translation_methods');
Assert::keyExists($options, 'lang_dir_path');

$this->disk = $disk ?? resolve(Filesystem::class);
$this->paths = $options['paths'];
$this->excludedPaths = $options['excluded_paths'];
$this->translationMethods = $options['translation_methods'];
$this->langDirPath = $options['lang_dir_path'];
}

public function all(): array
Expand Down Expand Up @@ -63,7 +66,7 @@ private function files(): array

private function existingPhpTranslations(): array
{
return Collection::make($this->disk->allFiles(resource_path('lang')))
return Collection::make($this->disk->allFiles($this->langDirPath))
->filter(fn ($file) => $file->getExtension() === 'php')
->reduce(function ($carry, $file) {
$translations = $this->disk->getRequire($file->getRealPath());
Expand Down
1 change: 1 addition & 0 deletions tests/RequiredTranslationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function it_finds_all_required_translations(): void
'paths' => [__DIR__ . '/fixtures/test-files'],
'excluded_paths' => [],
'translation_methods' => ['__', 'trans', 'trans_choice', '@lang', 'Lang::get'],
'lang_dir_path' => base_path('lang'),
],
new Filesystem(),
);
Expand Down

0 comments on commit 7e37aaa

Please sign in to comment.