From a6d3f9605c5700045c6932c55452bdccfeefb047 Mon Sep 17 00:00:00 2001 From: askdkc Date: Wed, 17 Jan 2024 10:29:26 +0900 Subject: [PATCH] Update to Support Laravel 11 --- src/Commands/BreezejpCommand.php | 51 ++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/src/Commands/BreezejpCommand.php b/src/Commands/BreezejpCommand.php index 94d4be7..7303166 100644 --- a/src/Commands/BreezejpCommand.php +++ b/src/Commands/BreezejpCommand.php @@ -25,17 +25,55 @@ public function handle(): int (new Filesystem)->ensureDirectoryExists(lang_path()); (new Filesystem)->copyDirectory(__DIR__.'/../../stubs/lang/', lang_path()); - $this->info('config/app.phpのlocaleをjaにします'); + $envfile = file_get_contents(base_path('.env')); + + if (strpos($envfile, 'APP_FAKER_LOCALE') == false) { + $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); + $configfile = str_replace("'faker_locale' => 'en_US'", "'faker_locale' => 'ja_JP'", $configfile); + $configfile = str_replace("'timezone' => 'UTC'", "'timezone' => 'Asia/Tokyo'", $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'; + + if (PHP_OS_FAMILY == 'Darwin') { + exec("open {$repoUrl}"); + } + if (PHP_OS_FAMILY == 'Windows') { + exec("start {$repoUrl}"); + } + if (PHP_OS_FAMILY == 'Linux') { + exec("xdg-open {$repoUrl}"); + } + + $this->line('Thank you! / ありがとう💓'); + } + + $this->info('日本語ファイルのインストールが完了しました!'); + + return self::SUCCESS; + + } + + // For Laravel 11 and above + $this->info('.envのAPP_LOCALEやAPP_TIMEZONEを日本にします'); // Read the contents of the file into a string - $configfile = file_get_contents(base_path('config/app.php')); + $configfile = file_get_contents(base_path('.env')); // Modify the contents of the string - $configfile = str_replace("'locale' => 'en'", "'locale' => 'ja'", $configfile); - $configfile = str_replace("'faker_locale' => 'en_US'", "'faker_locale' => 'ja_JP'", $configfile); - $configfile = str_replace("'timezone' => 'UTC'", "'timezone' => 'Asia/Tokyo'", $configfile); + $configfile = str_replace('APP_LOCALE=en', 'APP_LOCALE=ja', $configfile); + $configfile = str_replace('APP_FAKER_LOCALE=en_US', 'APP_FAKER_LOCALE=ja_JP', $configfile); + $configfile = str_replace('APP_TIMEZONE=UTC', 'APP_TIMEZONE=Asia/Tokyo', $configfile); // Save the modified contents back to the file - file_put_contents(base_path('config/app.php'), $configfile); + file_put_contents(base_path('.env'), $configfile); if ($this->confirm('GitHubリポジトリにスターの御協力をお願いします🙏', true)) { $repoUrl = 'https://github.com/askdkc/breezejp'; @@ -56,5 +94,6 @@ public function handle(): int $this->info('日本語ファイルのインストールが完了しました!'); return self::SUCCESS; + } }