From e4b8f2b5b624bb6a908f1f7cf1efbf200e11d0f4 Mon Sep 17 00:00:00 2001 From: Jannes Behrens Date: Mon, 17 Jul 2023 10:36:34 +0200 Subject: [PATCH 1/3] Remove locale path from default locale --- src/Localize/TransRoute.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Localize/TransRoute.php b/src/Localize/TransRoute.php index 2da6002..a60895b 100644 --- a/src/Localize/TransRoute.php +++ b/src/Localize/TransRoute.php @@ -44,7 +44,7 @@ public function getLocale() return $locale; } - if (! isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { + if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { return $this->getFallbackLocale(); } @@ -111,10 +111,17 @@ protected function makeTransRouteForLocale($uri, $action, $locale) { $uri = $this->compileUri($uri, $locale); - $route = Route::prefix($locale) - ->as("{$locale}.") - ->get($uri, $action) - ->translator(fn ($locale) => request()->route()->parameters()); + if ($locale != $this->getFallbackLocale()) { + $route = Route::prefix($locale) + ->as("{$locale}.") + ->get($uri, $action) + ->translator(fn ($locale) => request()->route()->parameters()); + } else { + $route = Route::as("{$locale}.") + ->get($uri, $action) + ->translator(fn ($locale) => request()->route()->parameters()); + } + return $route; } From bd4de7ee30b6691637d1646db1c095e02a239d00 Mon Sep 17 00:00:00 2001 From: Jannes Behrens Date: Mon, 17 Jul 2023 10:53:42 +0200 Subject: [PATCH 2/3] tests --- tests/Localize/LocalizeTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Localize/LocalizeTest.php b/tests/Localize/LocalizeTest.php index d9617e7..2031b1c 100644 --- a/tests/Localize/LocalizeTest.php +++ b/tests/Localize/LocalizeTest.php @@ -38,12 +38,12 @@ public function it_returns_translated_routes() } /** @test */ - public function it_adds_locale_route_prefix() + public function it_adds_locale_route_prefix_for_secondary_language() { Route::trans('home', fn () => null); foreach (Route::getRoutes()->getRoutes() as $route) { - $this->assertContains(explode('/', $route->uri)[0], ['de', 'en']); + $this->assertContains(explode('/', $route->uri())[0], ['de', 'home']); } } @@ -70,7 +70,7 @@ public function test_transle_macro() Request::setRouteResolver(fn () => $route); $this->assertStringEndsWith('de/home', route($route->getName())); - $this->assertStringEndsWith('en/home', $route->translate('en')); + $this->assertStringEndsWith('home', $route->translate('en')); } /** @test */ From 444fdd6f6e79d80ae444a8c3c4a86a7c0a48ff16 Mon Sep 17 00:00:00 2001 From: Jannes Behrens Date: Mon, 17 Jul 2023 10:54:39 +0200 Subject: [PATCH 3/3] wip --- .github/workflows/tests.yml | 46 +++---------------------------------- 1 file changed, 3 insertions(+), 43 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 02837f3..1a9f4c5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,8 +13,8 @@ jobs: strategy: fail-fast: true matrix: - php: [7.4, 8.0] - laravel: [7.*, 8.*] + php: [8.0] + laravel: [8.*] stability: [prefer-lowest, prefer-stable] name: @@ -49,44 +49,4 @@ jobs: composer update --${{ matrix.stability }} --prefer-dist --no-interaction - name: Run PHP tests via PHPUnit - run: vendor/bin/phpunit - windows_tests: - runs-on: windows-latest - strategy: - fail-fast: true - matrix: - php: [7.4] - laravel: [7.*] - stability: [prefer-stable] - include: - - laravel: 7.* - name: p ${{ matrix.php }} - l ${{ matrix.laravel }} - Windows - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Cache dependencies - uses: actions/cache@v1 - with: - path: ~/.composer/cache/files - key: - dependencies-laravel-${{ matrix.laravel }}-php-${{ - matrix.php }}-composer-${{ hashFiles('composer.json') }} - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: - dom, curl, libxml, mbstring, zip, pdo, sqlite, pdo_sqlite, - bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo - tools: composer:v2 - coverage: none - - - name: Install dependencies - run: | - composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update - composer update --${{ matrix.stability }} --prefer-dist --no-interaction - - - name: Run PHP tests via PHPUnit - run: vendor/bin/phpunit + run: vendor/bin/phpunit \ No newline at end of file