From b68bb3a038db7c12954d62cefb7d2ca4c80dde52 Mon Sep 17 00:00:00 2001 From: dkc Date: Fri, 16 Dec 2022 21:13:00 +0900 Subject: [PATCH 1/4] Add Test to check locale update --- tests/CommandTest.php | 11 +++++++++++ tests/TestCase.php | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/tests/CommandTest.php b/tests/CommandTest.php index a02a7ce..6150750 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) From 658e87699660aa1c102e832ac9d5e32f914587f1 Mon Sep 17 00:00:00 2001 From: dkc Date: Fri, 16 Dec 2022 21:13:13 +0900 Subject: [PATCH 2/4] Add Auto Locale Update Feature --- src/Commands/BreezejpCommand.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Commands/BreezejpCommand.php b/src/Commands/BreezejpCommand.php index 3a41a21..d19d9d6 100644 --- a/src/Commands/BreezejpCommand.php +++ b/src/Commands/BreezejpCommand.php @@ -18,6 +18,17 @@ 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'; From 5273b948016f90d7df3d08b1bee57d5bf8ddaa5b Mon Sep 17 00:00:00 2001 From: dkc Date: Fri, 16 Dec 2022 21:13:16 +0900 Subject: [PATCH 3/4] Update README.md --- README.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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', ------------ +-------------------------------- ``` ### 動作確認 From 859ea06f3590bed8d150ea16aa924ab862c524f7 Mon Sep 17 00:00:00 2001 From: askdkc Date: Fri, 16 Dec 2022 12:13:44 +0000 Subject: [PATCH 4/4] Fix styling --- src/Commands/BreezejpCommand.php | 1 - tests/CommandTest.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Commands/BreezejpCommand.php b/src/Commands/BreezejpCommand.php index d19d9d6..3bb93c6 100644 --- a/src/Commands/BreezejpCommand.php +++ b/src/Commands/BreezejpCommand.php @@ -28,7 +28,6 @@ public function handle(): int // 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 6150750..06afcdc 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -14,7 +14,7 @@ $this->assertFileExists(base_path('lang/ja/validation.php')); }); -test('breezejp command successfully update config/app.php locale to ja', function (){ +test('breezejp command successfully update config/app.php locale to ja', function () { $this->artisan('breezejp') ->expectsOutput('Laravel Breeze用に日本語翻訳ファイルを準備します') ->expectsConfirmation('GitHubリポジトリにスターの御協力をお願いします🙏', 'no')