Skip to content

Commit

Permalink
Merge pull request #7 from kerwin-wildsea/fix/notification-translation
Browse files Browse the repository at this point in the history
Added logic to LanguageController for showing "Language changed" notification in the newly set language
  • Loading branch information
3x1io authored Nov 21, 2024
2 parents a40b786 + 14238f8 commit cdca2db
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Http/Controllers/LanguageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function index(Request $request): RedirectResponse
}

Notification::make()
->title(trans('filament-language-switcher::translation.notification'))
->title(trans('filament-language-switcher::translation.notification', locale: $request->get('lang')))
->icon('heroicon-o-check-circle')
->iconColor('success')
->send();
Expand Down
23 changes: 12 additions & 11 deletions tests/src/LanguageSwitcherTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

use Illuminate\Database\Eloquent\Relations\Relation;

use Filament\Notifications\Notification;
use Illuminate\Support\Str;
use TomatoPHP\FilamentLanguageSwitcher\Tests\Models\User;

use function Pest\Laravel\actingAs;
use function Pest\Laravel\get;

Expand Down Expand Up @@ -62,20 +62,21 @@
expect($currentLang)->toBeTrue();
});

it('can switch language while using morphMap', function () {
// Register Relation MorphMap
Relation::morphMap(['user' => get_class(auth()->user())]);

it('sends a notification in the newly selected language', function (string $locale) {
$response = get(route('languages.switcher', [
'model' => get_class(auth()->user()),
'model' => get_class(auth('web')->user()),
'model_id' => auth()->user()->id,
'lang' => 'ar',
'lang' => $locale,
]));

// Ensure the response status is OK (200)
$response->assertStatus(302);

$currentLang = auth('web')->user()->lang == 'ar';

expect($currentLang)->toBeTrue();
});
Notification::assertNotified(
Notification::make()
->title(trans('filament-language-switcher::translation.notification', locale: $locale))
->icon('heroicon-o-check-circle')
->iconColor('success')
);
})->with(['locale' => ['en', 'nl', 'ar', 'de']]);

0 comments on commit cdca2db

Please sign in to comment.