Skip to content

Commit

Permalink
feat: migrate Translation initialization process to support Laravel 1…
Browse files Browse the repository at this point in the history
…1 new application structure
  • Loading branch information
Gandhi11 committed Apr 23, 2024
1 parent 4e9dc26 commit 293b55a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 51 deletions.
17 changes: 3 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,10 @@ Require this package with composer:
composer require exolnet/laravel-translation
```

In Laravel 5.5, the service provider and facade will automatically get registered. For older versions of the framework, follow the steps below:
To make sure the routing system is using the one supporting the translation you must edit your `bootstrap/app.php` to change the Application class import

Register the service provider in `config/app.php`

```php
'providers' => [
// [...]
Exolnet\Translation\TranslationServiceProvider::class,
],
```

To make sure the routing system is using the one supporting the translation you must edit your `app/Http/Kernel.php` to add the usage of the custom user dispatcher

```php
use \Exolnet\Translation\Traits\CustomRouterDispatcher;
```bash
sed -i '' 's/Illuminate\\Foundation\\Application/Exolnet\\Translation\\Application/g' bootstrap/app.php
```

Now you're ready to start using the translation in your application.
Expand Down
18 changes: 18 additions & 0 deletions src/Application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Exolnet\Translation;

use Illuminate\Foundation\Application as LaravelApplication;

class Application extends LaravelApplication
{
/**
* {@inheritdoc}
*/
protected function registerBaseServiceProviders()
{
parent::registerBaseServiceProviders();

$this->register(new TranslationServiceProvider($this));
}
}
37 changes: 0 additions & 37 deletions src/Traits/CustomRouterDispatcher.php

This file was deleted.

7 changes: 7 additions & 0 deletions src/TranslationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Illuminate\Foundation\Events\LocaleUpdated;
use Illuminate\Routing\Route;
use Illuminate\Support\ServiceProvider;
use LogicException;

class TranslationServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -57,6 +58,12 @@ protected function offerPublishing(): void
*/
public function register()
{
if (! $this->app instanceof Application) {
throw new LogicException(
'The application must be an instance of ' . Application::class . ' to use the Translation package.'
);
}

$this->registerRouter();
$this->registerUrlGenerator();
$this->registerLocaleService();
Expand Down
5 changes: 5 additions & 0 deletions tests/Integration/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

namespace Exolnet\Translation\Tests\Integration;

use Exolnet\Translation\Application;
use Illuminate\Routing\Route;
use Orchestra\Testbench\TestCase as Orchestra;

abstract class TestCase extends Orchestra
{
protected function resolveApplication()
{
return new Application($this->getBasePath());
}
/**
* @return void
*/
Expand Down

0 comments on commit 293b55a

Please sign in to comment.