diff --git a/.editorconfig b/.editorconfig index 042d009..6537ca4 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,15 +1,15 @@ -# This file is for unifying the coding style for different editors and IDEs -# editorconfig.org - root = true [*] -end_of_line = lf charset = utf-8 +end_of_line = lf +insert_final_newline = true indent_style = space indent_size = 4 trim_trailing_whitespace = true -insert_final_newline = true [*.md] +trim_trailing_whitespace = false + +[*.{yml,yaml}] indent_size = 2 diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 92c6321..76b8c31 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -1,6 +1,6 @@ name: run-tests -on: [push] +on: [push, pull_request] jobs: tests: @@ -10,7 +10,6 @@ jobs: fail-fast: true matrix: php: [7.2, 7.3, 7.4] - laravel: [6.*] dependency-version: [prefer-lowest, prefer-stable] name: PHP ${{ matrix.php }} - ${{ matrix.dependency-version }} @@ -23,10 +22,10 @@ jobs: uses: actions/cache@v1 with: path: ~/.composer/cache/files - key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} + key: dependencies-laravel-7.x-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} - name: Setup PHP - uses: shivammathur/setup-php@v1 + uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} extensions: curl, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, iconv, intl diff --git a/LICENSE.md b/LICENSE.md index ac02644..4abed86 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015-2019 | ARCANEDEV - Localization +Copyright (c) 2015-2020 | ARCANEDEV - Localization Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index f55bce1..d0d37bc 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Feel free to check out the [releases](https://github.com/ARCANEDEV/Localization/ ### Features * Easy setup & configuration. - * Laravel `5.x | 6.x` are supported. + * Laravel `5.x | 6.x | 7.x` are supported. * SEO-Friendly (Search engine optimization). * New extended Router to manage your localized routes. * Translated Eloquent Models. @@ -52,7 +52,7 @@ If you discover any security related issues, please email arcanedev.maroc@gmail. - [All Contributors][link-contributors] [badge_license]: http://img.shields.io/packagist/l/arcanedev/localization.svg?style=flat-square -[badge_laravel]: https://img.shields.io/badge/Laravel-5.x%20|%206.x-orange.svg?style=flat-square +[badge_laravel]: https://img.shields.io/badge/Laravel-5.x|6.x|7.x-orange.svg?style=flat-square [badge_build]: https://img.shields.io/github/workflow/status/ARCANEDEV/Localization/run-tests?style=flat-square [badge_coverage]: https://img.shields.io/scrutinizer/coverage/g/ARCANEDEV/Localization.svg?style=flat-square [badge_quality]: https://img.shields.io/scrutinizer/g/ARCANEDEV/Localization.svg?style=flat-square diff --git a/_docs/1-Installation-and-Setup.md b/_docs/1-Installation-and-Setup.md index fa57b26..48694ec 100644 --- a/_docs/1-Installation-and-Setup.md +++ b/_docs/1-Installation-and-Setup.md @@ -6,49 +6,40 @@ 2. [Configuration](2-Configuration.md) 3. [Usage](3-Usage.md) 4. [FAQ](4-FAQ.md) - -## Server Requirements - -The Localization package has a few system requirements: - - - PHP >= 7.0 - -##### Optional - -PHP extensions: - - * **ext_intl :** Needed to use the `Locale` class. (http://php.net/manual/en/class.locale.php) ## Version Compatibility | Localization | Laravel | |:---------------------------------------|:--------------------------------------------------------------------------------------------------------------------| -| ![Localization v0.x][localization_0_x] | ![Laravel v5.0][laravel_5_0] ![Laravel v5.1][laravel_5_1] ![Laravel v5.2][laravel_5_2] ![Laravel v5.3][laravel_5_3] | -| ![Localization v1.x][localization_1_x] | ![Laravel v5.4][laravel_5_4] | -| ![Localization v2.x][localization_2_x] | ![Laravel v5.5][laravel_5_5] | -| ![Localization v3.x][localization_3_x] | ![Laravel v5.6][laravel_5_6] | -| ![Localization v4.x][localization_4_x] | ![Laravel v5.7][laravel_5_7] | +| ![Localization v7.x][localization_7_x] | ![Laravel v7.*][laravel_7_x] | +| ![Localization v6.x][localization_6_x] | ![Laravel v6.*][laravel_6_x] | | ![Localization v5.x][localization_5_x] | ![Laravel v5.8][laravel_5_8] | -| ![Localization v6.x][localization_6_x] | ![Laravel v6.0][laravel_6_0] | +| ![Localization v4.x][localization_4_x] | ![Laravel v5.7][laravel_5_7] | +| ![Localization v3.x][localization_3_x] | ![Laravel v5.6][laravel_5_6] | +| ![Localization v2.x][localization_2_x] | ![Laravel v5.5][laravel_5_5] | +| ![Localization v1.x][localization_1_x] | ![Laravel v5.4][laravel_5_4] | +| ![Localization v0.x][localization_0_x] | ![Laravel v5.0][laravel_5_0] ![Laravel v5.1][laravel_5_1] ![Laravel v5.2][laravel_5_2] ![Laravel v5.3][laravel_5_3] | -[laravel_5_0]: https://img.shields.io/badge/v5.0-supported-brightgreen.svg?style=flat-square "Laravel v5.0" -[laravel_5_1]: https://img.shields.io/badge/v5.1-supported-brightgreen.svg?style=flat-square "Laravel v5.1" -[laravel_5_2]: https://img.shields.io/badge/v5.2-supported-brightgreen.svg?style=flat-square "Laravel v5.2" -[laravel_5_3]: https://img.shields.io/badge/v5.3-supported-brightgreen.svg?style=flat-square "Laravel v5.3" -[laravel_5_4]: https://img.shields.io/badge/v5.4-supported-brightgreen.svg?style=flat-square "Laravel v5.4" -[laravel_5_5]: https://img.shields.io/badge/v5.5-supported-brightgreen.svg?style=flat-square "Laravel v5.5" -[laravel_5_6]: https://img.shields.io/badge/v5.6-supported-brightgreen.svg?style=flat-square "Laravel v5.6" -[laravel_5_7]: https://img.shields.io/badge/v5.7-supported-brightgreen.svg?style=flat-square "Laravel v5.7" +[laravel_7_x]: https://img.shields.io/badge/v7.x-supported-brightgreen.svg?style=flat-square "Laravel v7.*" +[laravel_6_x]: https://img.shields.io/badge/v6.x-supported-brightgreen.svg?style=flat-square "Laravel v6.*" [laravel_5_8]: https://img.shields.io/badge/v5.8-supported-brightgreen.svg?style=flat-square "Laravel v5.8" -[laravel_6_0]: https://img.shields.io/badge/v6.0-supported-brightgreen.svg?style=flat-square "Laravel v6.0" +[laravel_5_7]: https://img.shields.io/badge/v5.7-supported-brightgreen.svg?style=flat-square "Laravel v5.7" +[laravel_5_6]: https://img.shields.io/badge/v5.6-supported-brightgreen.svg?style=flat-square "Laravel v5.6" +[laravel_5_5]: https://img.shields.io/badge/v5.5-supported-brightgreen.svg?style=flat-square "Laravel v5.5" +[laravel_5_4]: https://img.shields.io/badge/v5.4-supported-brightgreen.svg?style=flat-square "Laravel v5.4" +[laravel_5_3]: https://img.shields.io/badge/v5.3-supported-brightgreen.svg?style=flat-square "Laravel v5.3" +[laravel_5_2]: https://img.shields.io/badge/v5.2-supported-brightgreen.svg?style=flat-square "Laravel v5.2" +[laravel_5_1]: https://img.shields.io/badge/v5.1-supported-brightgreen.svg?style=flat-square "Laravel v5.1" +[laravel_5_0]: https://img.shields.io/badge/v5.0-supported-brightgreen.svg?style=flat-square "Laravel v5.0" -[localization_0_x]: https://img.shields.io/badge/version-0.*-blue.svg?style=flat-square "Localization v0.*" -[localization_1_x]: https://img.shields.io/badge/version-1.*-blue.svg?style=flat-square "Localization v1.*" -[localization_2_x]: https://img.shields.io/badge/version-2.*-blue.svg?style=flat-square "Localization v2.*" -[localization_3_x]: https://img.shields.io/badge/version-3.*-blue.svg?style=flat-square "Localization v3.*" -[localization_4_x]: https://img.shields.io/badge/version-4.*-blue.svg?style=flat-square "Localization v4.*" -[localization_5_x]: https://img.shields.io/badge/version-5.*-blue.svg?style=flat-square "Localization v5.*" +[localization_7_x]: https://img.shields.io/badge/version-7.*-blue.svg?style=flat-square "Localization v7.*" [localization_6_x]: https://img.shields.io/badge/version-6.*-blue.svg?style=flat-square "Localization v6.*" +[localization_5_x]: https://img.shields.io/badge/version-5.*-blue.svg?style=flat-square "Localization v5.*" +[localization_4_x]: https://img.shields.io/badge/version-4.*-blue.svg?style=flat-square "Localization v4.*" +[localization_3_x]: https://img.shields.io/badge/version-3.*-blue.svg?style=flat-square "Localization v3.*" +[localization_2_x]: https://img.shields.io/badge/version-2.*-blue.svg?style=flat-square "Localization v2.*" +[localization_1_x]: https://img.shields.io/badge/version-1.*-blue.svg?style=flat-square "Localization v1.*" +[localization_0_x]: https://img.shields.io/badge/version-0.*-blue.svg?style=flat-square "Localization v0.*" ## Composer @@ -58,6 +49,10 @@ You can install this package via [Composer](http://getcomposer.org/) by running composer require arcanedev/localization ``` +PHP extensions: + + * **ext_intl :** Needed to use the `Locale` class. (http://php.net/manual/en/class.locale.php) + ## Laravel ### Setup diff --git a/_docs/2-Configuration.md b/_docs/2-Configuration.md index 5ad145f..b43d4e5 100644 --- a/_docs/2-Configuration.md +++ b/_docs/2-Configuration.md @@ -66,14 +66,10 @@ return [ | localized-routes | Allows to register all translatable routes. | | translation-redirect | Allows to translate the route attributes by using the translation event. | -## Ignored URI / Route +## Ignored URI/Route from localization ```php - 'ignored-uri' => [ - // - ], - - 'ignored-routes' => [ + 'ignored-redirection' => [ // ], ``` diff --git a/composer.json b/composer.json index 3a1f69d..597970d 100644 --- a/composer.json +++ b/composer.json @@ -14,15 +14,15 @@ "type": "library", "license": "MIT", "require": { - "php": ">=7.2.0", + "php": "^7.2.5", "ext-json": "*", - "arcanedev/support": "^5.1" + "arcanedev/support": "^7.0" }, "require-dev": { "ext-intl": "*", - "orchestra/testbench": "^4.0", + "orchestra/testbench": "^5.0", "mockery/mockery": "^1.3.1", - "phpunit/phpunit": "^8.0" + "phpunit/phpunit": "^8.5|^9.0" }, "autoload": { "psr-4": { @@ -45,5 +45,7 @@ }, "suggest": { "ext-intl": "Use Intl extension for 'Locale' class (an identifier used to get language)." - } + }, + "minimum-stability": "dev", + "prefer-stable": true } diff --git a/config/localization.php b/config/localization.php index f68daa0..ff3cd50 100644 --- a/config/localization.php +++ b/config/localization.php @@ -33,15 +33,11 @@ ], /* ----------------------------------------------------------------- - | Ignored URI/Routes from localization + | Ignored URI/Route from localization | ----------------------------------------------------------------- */ - 'ignored-uri' => [ - // - ], - - 'ignored-routes' => [ + 'ignored-redirection' => [ // ], diff --git a/src/LocalizationServiceProvider.php b/src/LocalizationServiceProvider.php index 8d8a925..b815f41 100644 --- a/src/LocalizationServiceProvider.php +++ b/src/LocalizationServiceProvider.php @@ -48,7 +48,11 @@ public function register(): void */ public function boot(): void { - $this->publishConfig(); - $this->publishViews(); + $this->loadViews(); + + if ($this->app->runningInConsole()) { + $this->publishConfig(); + $this->publishViews(); + } } } diff --git a/src/Middleware/Middleware.php b/src/Middleware/Middleware.php index 9bc3a7a..e655443 100644 --- a/src/Middleware/Middleware.php +++ b/src/Middleware/Middleware.php @@ -95,6 +95,16 @@ protected function hideDefaultLocaleInURL() return $this->localization->isDefaultLocaleHiddenInUrl(); } + /** + * Get the ignored URI/Route. + * + * @return array + */ + protected function getIgnoredRedirection(): array + { + return config('localization.ignored-redirection', []); + } + /* ----------------------------------------------------------------- | Check Methods | ----------------------------------------------------------------- @@ -122,14 +132,17 @@ protected function isDefaultLocaleHidden($locale) protected function shouldIgnore(Request $request): bool { foreach ($this->except as $except) { - if ($except !== '/') + if ($except !== '/') { $except = trim($except, '/'); + } - if ($request->is($except)) + if ($request->is($except)) { return true; + } - if ($request->routeIs($except)) + if ($request->routeIs($except)) { return true; + } } return false; @@ -166,17 +179,4 @@ protected function makeRedirectResponse($url, $code = null) { return new RedirectResponse($url, $code ?? config('localization.redirection-code', 302), ['Vary' => 'Accept-Language']); } - - /** - * The URIs or route names that should not be redirected. - * - * @return array - */ - protected function getIgnoredRedirection(): array - { - return array_merge( - config('localization.ignored-uri', []), - config('localization.ignored-routes', []) - ); - } } diff --git a/src/Providers/RoutingServiceProvider.php b/src/Providers/RoutingServiceProvider.php index eaf2b8f..30c8f32 100644 --- a/src/Providers/RoutingServiceProvider.php +++ b/src/Providers/RoutingServiceProvider.php @@ -4,9 +4,11 @@ namespace Arcanedev\Localization\Providers; -use Arcanedev\Localization\Middleware; -use Arcanedev\Support\Providers\RouteServiceProvider as ServiceProvider; +use Arcanedev\Localization\Middleware\{ + LocaleCookieRedirect, LocaleSessionRedirect, LocalizationRedirect, LocalizationRoutes, TranslationRedirect +}; use Arcanedev\Localization\Routing\Router; +use Arcanedev\Support\Providers\RouteServiceProvider as ServiceProvider; /** * Class RoutingServiceProvider @@ -29,11 +31,11 @@ class RoutingServiceProvider extends ServiceProvider * @var array */ protected $routeMiddleware = [ - 'localization-session-redirect' => Middleware\LocaleSessionRedirect::class, - 'localization-cookie-redirect' => Middleware\LocaleCookieRedirect::class, - 'localization-redirect' => Middleware\LocalizationRedirect::class, - 'localized-routes' => Middleware\LocalizationRoutes::class, - 'translation-redirect' => Middleware\TranslationRedirect::class, + 'localization-session-redirect' => LocaleSessionRedirect::class, + 'localization-cookie-redirect' => LocaleCookieRedirect::class, + 'localization-redirect' => LocalizationRedirect::class, + 'localized-routes' => LocalizationRoutes::class, + 'translation-redirect' => TranslationRedirect::class, ]; /* ----------------------------------------------------------------- @@ -46,8 +48,13 @@ class RoutingServiceProvider extends ServiceProvider */ public function register(): void { - $this->app['router']->mixin(new Router); + /** @var \Illuminate\Routing\Router $router */ + $router = $this->app['router']; + + $router->mixin(new Router); - parent::register(); + foreach ($this->routeMiddleware as $name => $class) { + $router->aliasMiddleware($name, $class); + } } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 79b4e19..ca4154b 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -92,7 +92,7 @@ protected function getEnvironmentSetUp($app): void $translator->getLoader()->addNamespace( 'localization', - realpath(__DIR__).DS.'fixtures'.DS.'lang' + realpath(__DIR__).DIRECTORY_SEPARATOR.'fixtures'.DIRECTORY_SEPARATOR.'lang' ); $translator->load('localization', 'routes', 'en'); diff --git a/tests/fixtures/migrations/2017_06_01_000000_create_translatable_table.php b/tests/fixtures/migrations/2017_06_01_000000_create_translatable_table.php index 6f4ddea..64f18ec 100644 --- a/tests/fixtures/migrations/2017_06_01_000000_create_translatable_table.php +++ b/tests/fixtures/migrations/2017_06_01_000000_create_translatable_table.php @@ -14,6 +14,7 @@ class CreateTranslatableTable extends Migration | Properties | ----------------------------------------------------------------- */ + /** * The table name. * @@ -31,7 +32,7 @@ class CreateTranslatableTable extends Migration */ public function up(): void { - $this->createSchema(function (Blueprint $table) { + $this->createSchema(function (Blueprint $table): void { $table->increments('id'); $table->string('name'); $table->string('slug')->nullable(); diff --git a/resources/views/navbar.blade.php b/views/navbar.blade.php similarity index 100% rename from resources/views/navbar.blade.php rename to views/navbar.blade.php