diff --git a/app/Http/Middleware/SetLocale.php b/app/Http/Middleware/SetLocale.php index be2fb00..cd84dcc 100644 --- a/app/Http/Middleware/SetLocale.php +++ b/app/Http/Middleware/SetLocale.php @@ -17,10 +17,15 @@ class SetLocale */ public function handle(Request $request, Closure $next): Response { - if (Session::has('locale')) { + $locale = $request->query('lang'); + + if ($locale && in_array($locale, config('app.available_locales'))) { + App::setLocale($locale); + Session::put('locale', $locale); + } elseif (Session::has('locale')) { App::setLocale(Session::get('locale')); } else { - App::setLocale('en'); // Default locale + App::setLocale(config('app.fallback_locale', 'en')); } return $next($request); diff --git a/config/app.php b/config/app.php index 21392db..77d559c 100644 --- a/config/app.php +++ b/config/app.php @@ -84,6 +84,19 @@ return [ 'faker_locale' => env('APP_FAKER_LOCALE', 'en_US'), + /* + |-------------------------------------------------------------------------- + | Application Available Locales + |-------------------------------------------------------------------------- + | + | The application locales that are available for your application. + | + */ + + 'available_locales' => [ + 'en', 'ru', 'tk' + ], + /* |-------------------------------------------------------------------------- | Encryption Key diff --git a/database/seeders/UsersTableSeeder.php b/database/seeders/UsersTableSeeder.php index 75742aa..0f52728 100644 --- a/database/seeders/UsersTableSeeder.php +++ b/database/seeders/UsersTableSeeder.php @@ -3,6 +3,7 @@ namespace Database\Seeders; use App\Models\User; +use App\Models\UserRole; use Illuminate\Database\Seeder; class UsersTableSeeder extends Seeder @@ -16,6 +17,7 @@ class UsersTableSeeder extends Seeder 'name' => 'nurmuhammet', 'email' => 'nurmuhammet@mail.com', 'password' => bcrypt('payload10'), + 'role' => UserRole::ADMIN, ]); } } diff --git a/public/web/assets/js/custom.js b/public/web/assets/js/custom.js index adee3c4..f808cdb 100644 --- a/public/web/assets/js/custom.js +++ b/public/web/assets/js/custom.js @@ -492,6 +492,15 @@ } }); + // Language Switcher + $('#language-switcher button').on('click', function (e) { + $(this).addClass('active').siblings().removeClass('active'); + var lang = $(this).attr('data-lang'); + var currentUrl = new URL(window.location.href); + currentUrl.searchParams.set('lang', lang); + window.location.href = currentUrl.toString(); + }); + ///============= * Custom Cursor =============\\\ var ball = document.getElementById("cursor-ball"); var cursorText = document.getElementById("cursor-text"); diff --git a/resources/lang/en/app.php b/resources/lang/en/app.php index 6ff81fb..4fbdb3d 100644 --- a/resources/lang/en/app.php +++ b/resources/lang/en/app.php @@ -37,4 +37,15 @@ return [ 'Manage Solutions' => 'Manage Solutions', 'Success Section' => 'Success Section', 'Settings' => 'Settings', -]; \ No newline at end of file + '|' => '|', + 'Gujurly Inžener logo' => 'Gujurly Inžener logo', + 'Comments' => 'Comments', + 'No comments yet' => 'No comments yet', + 'Post Comment' => 'Post Comment', + 'Required fields are marked' => 'Required fields are marked', + 'Full Name' => 'Full Name', + 'Title' => 'Title', + 'Type your comments....' => 'Type your comments....', + 'Submit Comment' => 'Submit Comment', + 'Recent Blog' => 'Recent Blog', +]; diff --git a/resources/lang/ru/app.php b/resources/lang/ru/app.php index ee33371..341fc22 100644 --- a/resources/lang/ru/app.php +++ b/resources/lang/ru/app.php @@ -37,4 +37,15 @@ return [ 'Manage Solutions' => 'Управление решениями', 'Success Section' => 'Раздел «Успех»', 'Settings' => 'Настройки', -]; \ No newline at end of file + '|' => '|', + 'Gujurly Inžener logo' => 'Логотип Gujurly Inžener', + 'Comments' => 'Комментарии', + 'No comments yet' => 'Пока нет комментариев', + 'Post Comment' => 'Оставить комментарий', + 'Required fields are marked' => 'Обязательные поля отмечены', + 'Full Name' => 'Полное имя', + 'Title' => 'Заголовок', + 'Type your comments....' => 'Введите ваши комментарии....', + 'Submit Comment' => 'Отправить комментарий', + 'Recent Blog' => 'Последние новости блога', +]; diff --git a/resources/lang/tk/app.php b/resources/lang/tk/app.php index cdf4a3e..c1703d3 100644 --- a/resources/lang/tk/app.php +++ b/resources/lang/tk/app.php @@ -37,4 +37,15 @@ return [ 'Manage Solutions' => 'Çözgütleri dolandyrmak', 'Success Section' => 'Üstünlik bölümi', 'Settings' => 'Sazlamalar', -]; \ No newline at end of file + '|' => '|', + 'Gujurly Inžener logo' => 'Gujurly Inžener logotipi', + 'Comments' => 'Teswirler', + 'No comments yet' => 'Heniz teswir ýok', + 'Post Comment' => 'Teswir goşmak', + 'Required fields are marked' => 'Hökmany meýdançalar bellik edilen', + 'Full Name' => 'Doly ady', + 'Title' => 'Ady', + 'Type your comments....' => 'Teswirleriňizi ýazyň....', + 'Submit Comment' => 'Teswir ibermek', + 'Recent Blog' => 'Soňky bloglar', +]; diff --git a/resources/views/web/layouts/settings-button.blade.php b/resources/views/web/layouts/settings-button.blade.php index 664e558..5c8a0b7 100644 --- a/resources/views/web/layouts/settings-button.blade.php +++ b/resources/views/web/layouts/settings-button.blade.php @@ -12,6 +12,14 @@ +
+
{{ __('Language') }}
+
+ + + +
+
diff --git a/resources/views/web/pages/news/show.blade.php b/resources/views/web/pages/news/show.blade.php index ff001da..f8cc3e6 100644 --- a/resources/views/web/pages/news/show.blade.php +++ b/resources/views/web/pages/news/show.blade.php @@ -9,8 +9,8 @@ @@ -39,7 +39,7 @@
-

Comments ({{ $news->comments->count() }})

+

{{ __('Comments') }} ({{ $news->comments->count() }})

@forelse ($news->comments as $comment)
@@ -54,35 +54,35 @@
@empty -

No comments yet

+

{{ __('No comments yet') }}

@endforelse
-

Post Comment

-

Required fields are marked

+

{{ __('Post Comment') }}

+

{{ __('Required fields are marked') }}

@csrf
- +
- +
- +
- +
@@ -95,7 +95,7 @@
-

Recent Blog

+

{{ __('Recent Blog') }}

@foreach($recentNews as $news)
diff --git a/routes/web.php b/routes/web.php index ee4432c..2c56c5e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -53,5 +53,6 @@ Route::get('privacy-and-policy', [LegalPageController::class, 'privacy'])->name( // Language Switcher Route::get('locale/{locale}', function ($locale) { Session::put('locale', $locale); + return redirect()->back(); })->name('locale.switch');