Skip to content

Commit

Permalink
Merge pull request #34 from askdkc/add-config-update
Browse files Browse the repository at this point in the history
Add Auto Locale Update
  • Loading branch information
askdkc authored Dec 16, 2022
2 parents 38f4b10 + 859ea06 commit 1450243
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ php artisan breezejp

出力内容:
Laravel Breeze用に日本語翻訳ファイルを準備します
config/app.phpのlocaleをjaにします

GitHubリポジトリにスターの御協力をお願いします🙏 (yes/no) [yes]:

Expand All @@ -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',
-----------
--------------------------------
```

### 動作確認
Expand Down
10 changes: 10 additions & 0 deletions src/Commands/BreezejpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
11 changes: 11 additions & 0 deletions tests/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
5 changes: 5 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1450243

Please sign in to comment.