diff --git a/README.md b/README.md index 787e60d..6e0d5b4 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ php artisan breezejp 出力内容: Laravel Breeze用に日本語翻訳ファイルを準備します +config/app.phpのlocaleをjaにします GitHubリポジトリにスターの御協力をお願いします🙏 (yes/no) [yes]: @@ -70,16 +71,18 @@ Laravel Breeze用に日本語翻訳ファイルを準備します ``` ### Laravelの言語設定 -Laravelの設定ファイル`config/app.php`で日本語を選択します +BreezejpはLaravelの設定ファイル`config/app.php`のlocaleを自動でenからjaに変更します + +具体的にはインストール時にこうなります ```vim ----before--- +---config/app.php:インストール前--- 'locale' => 'en', ------------- +-------------------------------- ↓ ----after--- +---config/app.php:インストール後--- 'locale' => 'ja', ------------ +-------------------------------- ``` ### 動作確認 diff --git a/src/Commands/BreezejpCommand.php b/src/Commands/BreezejpCommand.php index 3a41a21..3bb93c6 100644 --- a/src/Commands/BreezejpCommand.php +++ b/src/Commands/BreezejpCommand.php @@ -18,6 +18,16 @@ public function handle(): int (new Filesystem)->ensureDirectoryExists(lang_path()); (new Filesystem)->copyDirectory(__DIR__.'/../../stubs/lang/', lang_path()); + $this->info('config/app.phpのlocaleをjaにします'); + // Read the contents of the file into a string + $configfile = file_get_contents(base_path('config/app.php')); + + // Modify the contents of the string + $configfile = str_replace("'locale' => 'en'", "'locale' => 'ja'", $configfile); + + // Save the modified contents back to the file + file_put_contents(base_path('config/app.php'), $configfile); + if ($this->confirm('GitHubリポジトリにスターの御協力をお願いします🙏', true)) { $repoUrl = 'https://github.com/askdkc/breezejp'; diff --git a/tests/CommandTest.php b/tests/CommandTest.php index a02a7ce..06afcdc 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -13,3 +13,14 @@ $this->assertFileExists(base_path('lang/ja/passwords.php')); $this->assertFileExists(base_path('lang/ja/validation.php')); }); + +test('breezejp command successfully update config/app.php locale to ja', function () { + $this->artisan('breezejp') + ->expectsOutput('Laravel Breeze用に日本語翻訳ファイルを準備します') + ->expectsConfirmation('GitHubリポジトリにスターの御協力をお願いします🙏', 'no') + ->expectsOutput('日本語ファイルのインストールが完了しました!') + ->assertExitCode(0); + + $configfile = file_get_contents(base_path('config/app.php')); + $this->assertStringContainsString("'locale' => 'ja'", $configfile); +}); diff --git a/tests/TestCase.php b/tests/TestCase.php index b8478c0..d051dbd 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -25,6 +25,11 @@ protected function setUp(): void unlink(__DIR__.'/../vendor/orchestra/testbench-core/laravel/lang/ja/validation.php'); rmdir(__DIR__.'/../vendor/orchestra/testbench-core/laravel/lang/ja'); } + + // config/app.phpのlocaleをenに戻す + $configfile = file_get_contents(__DIR__.'/../vendor/orchestra/testbench-core/laravel/config/app.php'); + $configfile = str_replace("'locale' => 'ja'", "'locale' => 'en'", $configfile); + file_put_contents(__DIR__.'/../vendor/orchestra/testbench-core/laravel/config/app.php', $configfile); } protected function getPackageProviders($app)