additionOfMultiLang

This commit is contained in:
UronShrestha 2024-06-18 15:28:01 +05:45
parent 949fee1678
commit 28921cc745
23 changed files with 284 additions and 116 deletions

View File

@ -0,0 +1,21 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
class LangController extends Controller
{
public function change(Request $request)
{
App::setlocale($request->lang);
session()->put('locale', $request->lang);
return redirect()->back();
}
}

View File

@ -1,29 +0,0 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Redirect;
class LocaleController extends Controller
{
public function setLocale($locale)
{
// Validate supported locales
$supportedLocales = ['en', 'np']; // Add more locales as needed
if (!in_array($locale, $supportedLocales)) {
abort(400, 'Unsupported locale');
}
// Set the application locale
App::setLocale($locale);
// Store the locale in session or cookie
session()->put('locale', $locale);
// Redirect back or to a specific route after setting locale
return Redirect::back();
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use Illuminate\Support\Facades\App;
class LangManager
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if (session()->has('locale')) {
App::setLocale(session()->get('locale'));
}
return $next($request);
}
}

View File

@ -11,7 +11,9 @@ return Application::configure(basePath: dirname(__DIR__))
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
//
$middleware->web(append: [
App\Http\Middleware\LangManager::class
]);
})
->withExceptions(function (Exceptions $exceptions) {
//
@ -19,5 +21,5 @@ return Application::configure(basePath: dirname(__DIR__))
$app->middleware([
// Other middleware,
\App\Http\Middleware\SetLocale::class,
\App\Http\Middleware\LangManager::class,
]);

44
lang/en/message.php Normal file
View File

@ -0,0 +1,44 @@
<?php
return[
"Dashboard"=> "Dashboard",
"Charts"=>"Charts",
"User Management"=>"User Management",
"All Users"=> "All Users",
"Add Users"=> "Add Users",
"UI Elements"=> "UI Elements",
"Forms"=>"Forms",
"Tables"=> "Tables",
"EXAMPLES"=>"EXAMPLES",
"Calendar"=> "Calendar",
"Gallery"=> "Gallery",
"Kanban Board"=> "Kanban Board",
"Mailbox"=> "Mailbox",
"Pages"=> "Pages",
"Extras"=> "Extras",
"Search"=>"Search",
"MISCELLANEOUS"=> "MISCELLANEOUS",
"Documentation"=>"Documentation",
"LABELS"=>"LABELS",
"Important"=>"Important",
"Informational"=>"Informational",
"Profile"=> "Profile",
"Logout"=> "Logout",
"Home"=>"Home",
"Contact"=> "Contact",
"List of Users"=> "List of Users",
"Send Email"=>"Send Email",
"Welcome to"=> "Welcome to",
"Dashboard v2"=>"Dashboard v2",
"Serial"=> "Serial",
"Email"=> "Email",
"Name"=> "Name",
"Role":=>"Role",
"Action"=>"Action",
"Edit"=> "Edit",
"Delete"=>"Delete",
"Username"=>"Username",
"Password"=>"Password",
"User Role"=> "User Role",
"Submit"=>"Submit"
];

View File

@ -1,3 +0,0 @@
{
"Dashboard":"ड्यासबोर्ड"
}

44
lang/ne/message.php Normal file
View File

@ -0,0 +1,44 @@
<?php
return [
"Dashboard" => "ड्यासबोर्ड",
"Charts" => "चार्टहरू",
"User Management" => "प्रयोगकर्ता व्यवस्थापन",
"All Users" => "सबै प्रयोगकर्ताहरू",
"Add Users" => "प्रयोगकर्ताहरू थप्नुहोस्",
"UI Elements" => "UI तत्त्वहरू",
"Forms" => "फारमहरू",
"Tables" => "तालिकाहरू",
"EXAMPLES" => "उदाहरणहरू",
"Calendar" => "पात्रो",
"Gallery" => "ग्यालरी",
"Kanban Board" => "कानबान बोर्ड",
"Mailbox" => "मेलबक्स",
"Pages" => "पृष्ठहरू",
"Extras" => "थप",
"Search" => "खोजी",
"MISCELLANEOUS" => "विविध",
"Documentation" => "कागजात",
"LABELS" => "लेबलहरू",
"Important" => "महत्त्वपूर्ण",
"Informational" => "सूचनात्मक",
"Profile" => "प्रोफाइल",
"Logout" => "लगआउट",
"Home" => "गृह",
"Contact" => "सम्पर्क",
"List of Users" => "प्रयोगकर्ताहरूको सूची",
"Send Email" => "इमेल पठाउनुहोस्",
"Welcome to" => " स्वागत छ",
"Dashboard v2" => "ड्यासबोर्ड v2",
"Serial" => "सिरियल",
"Email" => "इमेल",
"Name" => "नाम",
"Role" => "भूमिका",
"Action" => "कार्य",
"Edit" => "सम्पादन गर्नुहोस्",
"Delete" => "हटाउनुहोस्",
"Username" => "प्रयोगकर्ता नाम",
"Password" => "पासवर्ड",
"User Role" => "प्रयोगकर्ता भूमिका",
"Submit" => "पेश गर्नुहोस्"
];

View File

@ -0,0 +1,11 @@
<?php
// resources/lang/en/messages.php
return [
'user_added_success' => 'User Added Successfully',
'user_added_error' => 'User Added Unsuccessfully',
'user_updated_success' => 'User Updated Successfully',
'user_updated_error' => 'User is not Updated',
'email_sent_success' => 'Email Sent Successfully',
'email_sent_error' => 'An error occurred while sending the email.',
// Add more keys as needed
];

43
resources/lang/ne.json Normal file
View File

@ -0,0 +1,43 @@
{
"Dashboard": "ड्यासबोर्ड",
"Charts": "चार्टहरू",
"": "",
"User Management": "प्रयोगकर्ता व्यवस्थापन",
"All Users": "सबै प्रयोगकर्ताहरू",
"Add Users": "प्रयोगकर्ताहरू थप्नुहोस्",
"UI Elements": "UI तत्त्वहरू",
"Forms": "फारमहरू",
"Tables": "तालिकाहरू",
"EXAMPLES": "उदाहरणहरू",
"Calendar": "पात्रो",
"Gallery": "ग्यालरी",
"Kanban Board": "कानबान बोर्ड",
"Mailbox": "मेलबक्स",
"Pages": "पृष्ठहरू",
"Extras": "थप",
"Search": "खोजी",
"MISCELLANEOUS": "विविध",
"Documentation": "कागजात",
"LABELS": "लेबलहरू",
"Important": "महत्त्वपूर्ण",
"Informational": "सूचनात्मक",
"Profile": "प्रोफाइल",
"Logout": "लगआउट",
"Home": "गृह",
"Contact": "सम्पर्क",
"List of Users": "प्रयोगकर्ताहरूको सूची",
"Send Email": "इमेल पठाउनुहोस्",
"Welcome to": " स्वागत छ",
"Dashboard v2": "ड्यासबोर्ड v2",
"Serial": "सिरियल",
"Email": "इमेल",
"Name": "नाम",
"Role": "भूमिका",
"Action": "कार्य",
"Edit": "सम्पादन गर्नुहोस्",
"Delete": "हटाउनुहोस्",
"Username": "प्रयोगकर्ता नाम",
"Password": "पासवर्ड",
"User Role": "प्रयोगकर्ता भूमिका",
"Submit": "पेश गर्नुहोस्"
}

View File

@ -0,0 +1,13 @@
<?php
// resources/lang/en/messages.php
return [
"Dashboard" => "ड्यासबोर्ड",
'user_added_success' => 'प्रयोगकर्ता सफलतापूर्वक थपियो',
'user_added_error' => 'प्रयोगकर्ता थप्न असफल भयो',
'user_updated_success' => 'प्रयोगकर्ता सफलतापूर्वक अद्यावधिक गरियो',
'user_updated_error' => 'प्रयोगकर्ता अद्यावधिक गरिएन',
'email_sent_success' => 'इमेल सफलतापूर्वक पठाइयो',
'email_sent_error' => 'इमेल पठाउँदा त्रुटि भयो',
// Add more keys as needed
];

View File

@ -1,7 +0,0 @@
<?php
return [
'welcome' => 'Welcome',
'user_list' => 'List of Users',
// Add more translations here
];

View File

@ -1,7 +0,0 @@
<?php
return [
'welcome' => 'स्वागत छ',
'user_list' => 'प्रयोगकर्ताहरूको सूची',
// Add more translations here
];

View File

@ -78,6 +78,7 @@
<!-- REQUIRED SCRIPTS -->
<!-- jQuery -->
<script src="{{ asset('backend/plugins/jquery/jquery.min.js') }}"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<!-- Bootstrap -->
<script src="{{ asset('backend/plugins/bootstrap/js/bootstrap.bundle.min.js') }}"></script>
<!-- overlayScrollbars -->
@ -117,6 +118,8 @@
<script src="{{ asset('backend/plugins/toastr/toastr.min.js') }}"></script>
<script src="{{ asset('backend/plugins/sweetalert2/sweetalert2.min.js') }}"></script>
@yield('script')
@ -292,6 +295,15 @@
});
</script>
<script>
$('.changeLang').change(function() {
var url = "{{ route('changelang') }}";
window.location.href = url + "?lang=" + $(this).val();
});
</script>

View File

@ -6,12 +6,12 @@
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="m-0">Dashboard v2</h1>
<h1 class="m-0">{{ __('Dashboard v2') }} </h1>
</div><!-- /.col -->
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item"><a href="{{ url('/home') }}">Home</a></li>
<li class="breadcrumb-item active"><a href="#">Dashboard</a></li>
<li class="breadcrumb-item"><a href="{{ url('/home') }}">{{ __('Home') }}</a></li>
<li class="breadcrumb-item active"><a href="#">{{ __('Dashboard') }}</a></li>
</ol>
</div><!-- /.col -->
</div><!-- /.row -->
@ -90,7 +90,7 @@
<div class="col-md-12">
<div class="card">
<div class="card-header">
<h5 class="card-title"> {{ auth()->user()->role }} - Dashboard </h5>
<h5 class="card-title"> {{ auth()->user()->role }} - {{ __('Dashboard') }} </h5>
<div class="card-tools">
<button type="button" class="btn btn-tool" data-card-widget="collapse">
@ -111,7 +111,7 @@
<div class="card-body">
<div class="row">
<div class="col-md-8">
Welcome to {{ auth()->user()->role }} - Dashboard
{{ __('Welcome to') }} {{ auth()->user()->role }} - {{ __('Dashboard') }}
</div>
<!-- /.col -->

View File

@ -5,11 +5,11 @@
<a class="nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a>
</li>
<li class="nav-item d-none d-sm-inline-block">
<a href="{{ url('/home') }}" class="nav-link">Home</a>
<a href="{{ url('/home') }}" class="nav-link">{{ __('Home') }}</a>
</li>
<li class="nav-item d-none d-sm-inline-block">
<a href="#" class="nav-link">Contact</a>
<a href="#" class="nav-link">{{ __('Contact') }}</a>
</li>
</ul>
@ -42,17 +42,16 @@
<!-- Language Dropdown Menu -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" id="languageDropdown" data-toggle="dropdown" href="#"
role="button" aria-haspopup="true" aria-expanded="false">
<i class="fa fa-language"></i>
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="languageDropdown">
<a class="dropdown-item" href="#">English</a>
<a class="dropdown-item" href="#">Nepali</a>
<a class="dropdown-item" href="#">Spanish</a>
</div>
</li>
<form class="dflex">
<select class="form-control changeLang">
<option value="en" {{ session()->get('locale') == 'en' ? 'selected' : '' }}> English</option>
<option value="ne" {{ session()->get('locale') == 'ne' ? 'selected' : '' }}> Nepali</option>
</select>
</form>
<!-- Messages Dropdown Menu -->

View File

@ -63,7 +63,8 @@
<a href="#" class="nav-link">
<i class="nav-icon fas fa-copy"></i>
<p>
User Management
{{ __('User Management') }}
{{-- User Management --}}
<i class="fas fa-angle-left right"></i>
<span class="badge badge-info right">6</span>
</p>
@ -72,13 +73,13 @@
<li class="nav-item">
<a href="{{ '/all-user' }}" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>All Users</p>
<p> {{ __('All Users') }}</p>
</a>
</li>
<li class="nav-item">
<a href="{{ '/add-user' }}" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Add user</p>
<p> {{ __('Add Users') }}</p>
</a>
</li>
@ -91,7 +92,7 @@
<a href="#" class="nav-link">
<i class="nav-icon fas fa-chart-pie"></i>
<p>
Charts
{{ __('Charts') }}
<i class="right fas fa-angle-left"></i>
</p>
</a>
@ -126,7 +127,7 @@
<a href="#" class="nav-link">
<i class="nav-icon fas fa-tree"></i>
<p>
UI Elements
{{ __('UI Elements') }}
<i class="fas fa-angle-left right"></i>
</p>
</a>
@ -185,7 +186,7 @@
<a href="#" class="nav-link">
<i class="nav-icon fas fa-edit"></i>
<p>
Forms
{{ __('Forms') }}
<i class="fas fa-angle-left right"></i>
</p>
</a>
@ -220,7 +221,7 @@
<a href="#" class="nav-link">
<i class="nav-icon fas fa-table"></i>
<p>
Tables
{{ __('Tables') }}
<i class="fas fa-angle-left right"></i>
</p>
</a>
@ -245,12 +246,12 @@
</li>
</ul>
</li>
<li class="nav-header">EXAMPLES</li>
<li class="nav-header">{{ __('EXAMPLES') }}</li>
<li class="nav-item">
<a href="pages/calendar.html" class="nav-link">
<i class="nav-icon fas fa-calendar-alt"></i>
<p>
Calendar
{{ __('Calendar') }}
<span class="badge badge-info right">2</span>
</p>
</a>
@ -259,7 +260,7 @@
<a href="pages/gallery.html" class="nav-link">
<i class="nav-icon far fa-image"></i>
<p>
Gallery
{{ __('Gallery') }}
</p>
</a>
</li>
@ -267,7 +268,7 @@
<a href="pages/kanban.html" class="nav-link">
<i class="nav-icon fas fa-columns"></i>
<p>
Kanban Board
{{ __('Kanban Board') }}
</p>
</a>
</li>
@ -275,7 +276,7 @@
<a href="#" class="nav-link">
<i class="nav-icon far fa-envelope"></i>
<p>
Mailbox
{{ __('Mailbox') }}
<i class="fas fa-angle-left right"></i>
</p>
</a>
@ -304,7 +305,7 @@
<a href="#" class="nav-link">
<i class="nav-icon fas fa-book"></i>
<p>
Pages
{{ __('Pages') }}
<i class="fas fa-angle-left right"></i>
</p>
</a>
@ -375,7 +376,7 @@
<a href="#" class="nav-link">
<i class="nav-icon far fa-plus-square"></i>
<p>
Extras
{{ __('Extras') }}
<i class="fas fa-angle-left right"></i>
</p>
</a>
@ -504,7 +505,7 @@
<a href="#" class="nav-link">
<i class="nav-icon fas fa-search"></i>
<p>
Search
{{ __('Search') }}
<i class="fas fa-angle-left right"></i>
</p>
</a>
@ -523,7 +524,7 @@
</li>
</ul>
</li>
<li class="nav-header">MISCELLANEOUS</li>
<li class="nav-header"> {{ __('MISCELLANEOUS') }}</li>
<li class="nav-item">
<a href="iframe.html" class="nav-link">
<i class="nav-icon fas fa-ellipsis-h"></i>
@ -533,23 +534,23 @@
<li class="nav-item">
<a href="https://adminlte.io/docs/3.1/" class="nav-link">
<i class="nav-icon fas fa-file"></i>
<p>Documentation</p>
<p> {{ __('Documentation') }}</p>
</a>
</li>
</li>
<li class="nav-header">LABELS</li>
<li class="nav-header"> {{ __('LABELS') }}</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="nav-icon far fa-circle text-danger"></i>
<p class="text">Important</p>
<p class="text"> {{ __('Important') }}</p>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="nav-icon far fa-circle text-info"></i>
<p>Informational</p>
<p> {{ __('Informational') }} </p>
</a>
</li>
@endif
@ -557,7 +558,7 @@
<li class="nav-item">
<a href="#" class="nav-link">
<i class="nav-icon far fa-circle text-info"></i>
<p>Profile</p>
<p> {{ __('Profile') }}</p>
</a>
</li>

View File

@ -12,7 +12,7 @@
<div class="card">
<!-- /.card-header -->
<div class="card-header">
<h3 class="card-title">Add Users</h3>
<h3 class="card-title">{{ __('Add Users') }}</h3>
</div>
<!-- /.card-body -->
<div class="card-body">
@ -20,28 +20,31 @@
@csrf
<div class="form-group row">
<label for="inputUsername3" class="col-sm-2 col-form-label">Username</label>
<label for="inputUsername3"
class="col-sm-2 col-form-label">{{ __('Username') }}</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputUsername3" name="name"
placeholder="Enter your username" required>
</div>
</div>
<div class="form-group row">
<label for="inputEmail3" class="col-sm-2 col-form-label">Email</label>
<label for="inputEmail3" class="col-sm-2 col-form-label">{{ __('Email') }}</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="inputEmail3" name="email"
placeholder="Email" required>
</div>
</div>
<div class="form-group row">
<label for="inputPassword3" class="col-sm-2 col-form-label">Password</label>
<label for="inputPassword3"
class="col-sm-2 col-form-label">{{ __('Password') }}</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="inputPassword3" name="password"
placeholder="Password" required>
</div>
</div>
<div class="form-group row">
<label for="role" class="col-sm-2 col-form-label">User Role</label>
<label for="role" class="col-sm-2 col-form-label">{{ __('User Role') }}
</label>
<div class="col-sm-10">
<select class="form-control" name="role" id="exampleFormControlSelect1">
<option value="Admin">Admin</option>
@ -52,7 +55,7 @@
</div>
<div class="form-group row">
<div class="col-sm-10 offset-sm-2">
<button type="submit" class="btn btn-info">Submit</button>
<button type="submit" class="btn btn-info">{{ __('Submit') }}</button>
</div>
</div>
</form>

View File

@ -11,18 +11,18 @@
<div class="card">
<div class="card-header">
<h3 class="card-title">List of Users</h3>
<h3 class="card-title">{{ __('List of Users') }}</h3>
</div>
<!-- /.card-header -->
<div class="card-body">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>Serial </th>
<th>Name</th>
<th>Email</th>
<th>Role</th>
<th>Action</th>
<th>{{ __('Serial') }} </th>
<th>{{ __('Name') }}</th>
<th>{{ __('Email') }}</th>
<th>{{ __('Role') }}</th>
<th>{{ __('Action') }}</th>
</tr>
</thead>
<tbody>
@ -37,17 +37,18 @@
<td>
<a href="{{ url('edit-user', $row->id) }}"
class="btn btn-sm btn-success">Edit</a>
class="btn btn-sm btn-success">{{ __('Edit') }}</a>
<a href="{{ url('delete-user', $row->id) }}"
class="btn btn-sm btn-danger delete-btn">Delete</a>
class="btn btn-sm btn-danger delete-btn">{{ __('Delete') }}</a>
<form action="{{ route('send-email') }}" method="POST"
style="display:inline;">
@csrf
<input type="hidden" name="name" value="{{ $row->name }}">
<input type="hidden" name="email" value="{{ $row->email }}">
<button type="submit" class="btn btn-sm btn-primary">Send
Email</button>
<button type="submit"
class="btn btn-sm btn-primary">{{ __('Send Email') }}
</button>
@ -66,11 +67,11 @@
</tbody>
<tfoot>
<tr>
<th>Serial </th>
<th>Name</th>
<th>Email</th>
<th>Role</th>
<th>Action</th>
<th>{{ __('Serial') }} </th>
<th>{{ __('Name') }}</th>
<th>{{ __('Email') }}Email</th>
<th>{{ __('Role') }}</th>
<th>{{ __('Action') }}</th>
</tr>
</tfoot>
</table>

View File

@ -2,6 +2,8 @@
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\MailController;
use App\Http\Controllers\LangController;
use App\Http\Controllers\backend\UserController;
use Illuminate\Support\Facades\Route;
@ -67,11 +69,4 @@ Route::post('/send-email', [App\Http\Controllers\backend\UserController::class,
// Route for setting the locale
Route::get('/lang/{locale}', function ($locale) {
Session::put('locale', $locale);
return redirect()->back();
})->name('setLocale');
Route::get('set-locale/{locale}', [App\Http\Controllers\LocaleController::class, 'setLocale'])->name('setLocale');
Route::get('/lang/change', [App\Http\Controllers\LangController::class, 'change'])->name('changelang');