Skip to content

Commit

Permalink
Merge pull request #112 from askdkc/l11
Browse files Browse the repository at this point in the history
Support Laravel 11
  • Loading branch information
askdkc authored Jan 26, 2024
2 parents df3d892 + 7439068 commit fd37c23
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 20 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@ jobs:
matrix:
os: [ubuntu-latest]
php: [8.0, 8.1, 8.2, 8.3]
laravel: [10.*, 9.*]
stability: [prefer-lowest, prefer-stable]
laravel: [11.*, 10.*, 9.*]
stability: [prefer-stable]
include:
- laravel: 9.*
testbench: 7.*
- laravel: 10.*
testbench: 8.*
- laravel: 11.*
testbench: 9.*
exclude:
- laravel: 10.*
php: 8.0
- laravel: 11.*
php: 8.0
- laravel: 11.*
php: 8.1

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
[![Total Downloads](https://img.shields.io/packagist/dt/askdkc/breezejp.svg)](https://packagist.org/packages/askdkc/breezejp)
[![](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/askdkc)

## Laravel 11にも対応済みです(2024-01-26)

## これは何? TL;DR
Laravelを下記2コマンドだけで自動で日本語化できちゃうパッケージです👍
```bash
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
"require": {
"php": "^8.0",
"spatie/laravel-package-tools": "^1.14.0",
"illuminate/contracts": "^9.28|^10.0"
"illuminate/contracts": "^9.28|^10.0|^11.0"
},
"require-dev": {
"laravel/pint": "^1.4",
"nunomaduro/collision": "^6.0|^7.0",
"nunomaduro/larastan": "^2.0",
"orchestra/testbench": "^7.7|^8.0",
"pestphp/pest": "^1.22|^2.0",
"nunomaduro/collision": "^6.0|^7.0|^8.0",
"larastan/larastan": "^2.0",
"orchestra/testbench": "^7.7|^8.0|^9.0",
"pestphp/pest": "^1.22|^2.0|^3.0",
"phpstan/extension-installer": "^1.2",
"phpunit/phpunit": "^9.5.27|^10.0"
"phpunit/phpunit": "^9.5.27|^10.0|^11.0"
},
"autoload": {
"psr-4": {
Expand Down
51 changes: 45 additions & 6 deletions src/Commands/BreezejpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -56,5 +94,6 @@ public function handle(): int
$this->info('日本語ファイルのインストールが完了しました!');

return self::SUCCESS;

}
}
28 changes: 22 additions & 6 deletions tests/CommandTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

test('.env file exists', function () {
$this->assertFileExists(base_path('.env'));
});

test('breezejp command successfully run and see all the published files', closure: function () {
$this->artisan('breezejp')
->expectsOutput('Laravel Breeze用に日本語翻訳ファイルを準備します')
Expand All @@ -21,10 +25,17 @@
->expectsOutput('日本語ファイルのインストールが完了しました!')
->assertExitCode(0);

$configfile = file_get_contents(base_path('config/app.php'));
$this->assertStringContainsString("'locale' => 'ja'", $configfile);
$this->assertStringContainsString("'faker_locale' => 'ja_JP'", $configfile);
$this->assertStringContainsString("'timezone' => 'Asia/Tokyo'", $configfile);
if ((int) substr(Illuminate\Foundation\Application::VERSION, 0, 2) < 11) {
$configfile = file_get_contents(base_path('config/app.php'));
$this->assertStringContainsString("'locale' => 'ja'", $configfile);
$this->assertStringContainsString("'faker_locale' => 'ja_JP'", $configfile);
$this->assertStringContainsString("'timezone' => 'Asia/Tokyo'", $configfile);
} else { // For Laravel 11 and above
$configfile = file_get_contents(base_path('.env'));
$this->assertStringContainsString('APP_LOCALE=ja', $configfile);
$this->assertStringContainsString('APP_FAKER_LOCALE=ja_JP', $configfile);
$this->assertStringContainsString('APP_TIMEZONE=Asia/Tokyo', $configfile);
}
});

test('breezejp command successfully update config/app.php timezone to Asia/Tokyo', function () {
Expand All @@ -34,6 +45,11 @@
->expectsOutput('日本語ファイルのインストールが完了しました!')
->assertExitCode(0);

$configfile = file_get_contents(base_path('config/app.php'));
$this->assertStringContainsString("'timezone' => 'Asia/Tokyo'", $configfile);
if ((int) substr(Illuminate\Foundation\Application::VERSION, 0, 2) < 11) {
$configfile = file_get_contents(base_path('config/app.php'));
$this->assertStringContainsString("'timezone' => 'Asia/Tokyo'", $configfile);
} else { // For Laravel 11 and above
$configfile = file_get_contents(base_path('.env'));
$this->assertStringContainsString('APP_TIMEZONE=Asia/Tokyo', $configfile);
}
});
13 changes: 13 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ protected function setUp(): void
{
parent::setUp();

copy(__DIR__.'/../vendor/orchestra/testbench-core/laravel/.env.example', __DIR__.'/../vendor/orchestra/testbench-core/laravel/.env');

// テスト用のファイルが残ってたら消す(web.php)
if (is_file(__DIR__.'/../vendor/orchestra/testbench-core/laravel/routes/web.php')) {
unlink(__DIR__.'/../vendor/orchestra/testbench-core/laravel/routes/web.php');
Expand Down Expand Up @@ -56,6 +58,17 @@ protected function setUp(): void
file_put_contents(__DIR__.'/../vendor/orchestra/testbench-core/laravel/config/app.php', $configfile);
}

protected function tearDown(): void
{
parent::tearDown();

// テスト用のファイルが残ってたら消す(.env)
if (is_file(__DIR__.'/../vendor/orchestra/testbench-core/laravel/.env')) {
unlink(__DIR__.'/../vendor/orchestra/testbench-core/laravel/.env');
}

}

protected function getPackageProviders($app)
{
return [
Expand Down

0 comments on commit fd37c23

Please sign in to comment.