diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index 46f7b6f..c2801a1 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -1166,7 +1166,7 @@ RESULT; */ function fixUrlLang($url) { - if (app()->getLocale() != config('app.xlang.main')){ + if ( config('app.xlang.active') && app()->getLocale() != config('app.xlang.main')){ $welcome = \route('client.welcome'); return str_replace($welcome,$welcome .'/'.app()->getLocale(),$url); } diff --git a/app/Http/Controllers/CardController.php b/app/Http/Controllers/CardController.php index 4c5cd29..0277a78 100644 --- a/app/Http/Controllers/CardController.php +++ b/app/Http/Controllers/CardController.php @@ -12,6 +12,18 @@ use Illuminate\Http\Request; class CardController extends Controller { + + public function __construct() + { + + $this->middleware(function ($request, $next) { + if (\Session::has('locate')) { + app()->setLocale(\Session::get('locate')); + } + return $next($request); + }); + } + public function productCardToggle(Product $product) { diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php index f96d968..297bdc8 100644 --- a/app/Http/Controllers/ClientController.php +++ b/app/Http/Controllers/ClientController.php @@ -22,6 +22,23 @@ use Spatie\Tags\Tag; class ClientController extends Controller { + public function __construct() + { + + $this->middleware(function ($request, $next) { + + if ($request->attributes->get('set_lang') != true){ + app()->setLocale(config('app.locale')); + \Session::remove('locate'); + }elseif (\Session::has('locate')) { + app()->setLocale(\Session::get('locate')); + } + + return $next($request); + }); + + } + public $paginate = 12; // @@ -207,8 +224,10 @@ class ClientController extends Controller } - public function group(Group $group) + public function group($slug) { + + $group = Group::where('slug',$slug)->firstOrFail(); $area = 'group'; $title = $group->name; $subtitle = $group->subtitle; @@ -596,10 +615,10 @@ class ClientController extends Controller $args = []; foreach ($routes as $i => $route) { if ($route[0] == '{'){ - $args[] = $segments[$i]; + $args[] = $segments[$i+1]; } } -// dd($segments); + $args[]= $request; return $this->$method(...$args); } diff --git a/app/Http/Controllers/CustomerController.php b/app/Http/Controllers/CustomerController.php index db69d02..0f48eae 100644 --- a/app/Http/Controllers/CustomerController.php +++ b/app/Http/Controllers/CustomerController.php @@ -11,9 +11,22 @@ class CustomerController extends Controller // public function __construct() { - if (!auth('customer')->check()) { - return redirect()->route('client.sign-in'); - } + + + + $this->middleware(function ($request, $next) { + + if (!auth('customer')->check()) { + return redirect()->route('client.sign-in'); + } + + if (\Session::has('locate')) { + app()->setLocale(\Session::get('locate')); + } + + return $next($request); + }); + } public function profile() @@ -21,10 +34,12 @@ class CustomerController extends Controller $area = 'customer'; $title = __("Profile"); $subtitle = 'You information'; - return view('client.default-list', compact('area', 'title', 'subtitle'));return auth('customer')->user(); + return view('client.default-list', compact('area', 'title', 'subtitle')); + return auth('customer')->user(); } - public function save(Request $request){ + public function save(Request $request) + { $request->validate([ 'name' => ['required', 'string', 'max:255'], 'email' => ['required', 'string', 'email', 'max:255'], @@ -36,14 +51,15 @@ class CustomerController extends Controller $customer->name = $request->name; $customer->email = $request->email; $customer->mobile = $request->mobile; - if ($request->has('password') && trim($request->input('password')) != ''){ + if ($request->has('password') && trim($request->input('password')) != '') { $customer->password = bcrypt($request->password); } $customer->save(); return redirect()->route('client.profile')->with('message', __('Profile updated successfully')); } - public function invoice(Invoice $invoice){ + public function invoice(Invoice $invoice) + { return $invoice; } diff --git a/app/Http/Middleware/LangControl.php b/app/Http/Middleware/LangControl.php index 71b54c4..32d2cc6 100644 --- a/app/Http/Middleware/LangControl.php +++ b/app/Http/Middleware/LangControl.php @@ -20,6 +20,10 @@ class LangControl $segments = $request->segments(); if (strlen($segments[0]) == 2 && preg_match('/[A-Za-z]/', $segments[0])) { app()->setLocale($segments[0]); + + $request->attributes->set('set_lang', true); + \Session::put('locate',app()->getLocale()); + \Session::save(); } else { app()->setLocale(config('app.locale')); } @@ -30,7 +34,6 @@ class LangControl $newPath = '/' . implode('/', $segments); $newUrl = $request->root() . $newPath . ($request->getQueryString() ? '?'.$request->getQueryString() : ''); - $request->server->set('REQUEST_URI', $newPath); $request->initialize( $request->query->all(), $request->request->all(), @@ -40,6 +43,8 @@ class LangControl $request->server->all() ); + + return $next($request); } } diff --git a/resources/lang/fa.json b/resources/lang/fa.json index 9b13ec2..f0375f4 100644 --- a/resources/lang/fa.json +++ b/resources/lang/fa.json @@ -5,6 +5,7 @@ " seconds ago": "ثانیه قبل", "!": "", "$role": "", + "%name% sale in our shop by %price% %category.name%": "%name% حراج در فروشگاه با قیمت %price% %category.name%", "09xxxxxxxx": "", ":ADDRESS removed": ":ADDRESS حذف شد", ":COUNT Images uploaded successfully": ":COUNT تصویر بارگزاری شد", @@ -36,7 +37,7 @@ "Add new gallery": "افزودن یک گالری", "Add new group": "افزودن یک سرفصل", "Add new language": "افزودن یک زبان جدید", - "Add new menu": "", + "Add new menu": "افزودن فهرست جدید", "Add new post": "افزودن یک نوشته", "Add new product": "افزودن یک محصول", "Add new prop": "افزودن یک ویژگی", @@ -47,7 +48,7 @@ "Add new ticket": "افزودن یک تکیت", "Add new transport": "افزودن یک حمل و نقل", "Add new user": "افزودن یک کاربر", - "Add to \/ Remove from favorites": "", + "Add to \/ Remove from favorites": "افزودن به یا حذف از علاقه‌مندی ها", "Add to card": "افزودن به سبد خرید", "Add to compare list": "افزودن به مقایسه", "Add to setting": "به تنظیم اضافه کن", @@ -55,7 +56,9 @@ "Added by:": "اضافه شده توسط", "Added items view depends on theme part": "موارد اضافه شده بسته به نوع نمای انتخاب شده متفاوت خواهد بود", "Additional data": "اطلاعات تکمیلی", + "Address": "نشانی", "Address added to :CUSTOMER": "نشانی به :CUSTOMER اضافه شد", + "Address editor": "ویرایشگر نشانی", "Addresses": "نشانی‌ها", "Admin": "مدیر", "Advertise": "تبلیغ", @@ -95,7 +98,7 @@ "Category": "دسته", "Category name": "نام دسته", "Category slug": "نامک دسته", - "Change items sort": "", + "Change items sort": "تغییر ترتیب نمایش", "Change latitude and longitude": "تغییر طول و عرض جغرافیایی", "Check": "بررسی", "Check all": "انتخاب همه", @@ -216,7 +219,7 @@ "Image deleted successfully": "تصویر حذف شد", "Image uploaded successfully": "تصویر افزوده شد", "Images": "تصاویر", - "Increase \/ decrease by Admin": "", + "Increase \/ decrease by Admin": "افزودن / کاهش توسط مدیر سایت", "Index image": "تصویر شاخص", "Information": "اطلاعات", "Interaction": "تعامل", @@ -232,10 +235,10 @@ "Label": "برچسب", "Languages": "زبان‌ها", "Languages list": "فهرست زبان‌ها", - "Last month visitors devices": "", + "Last month visitors devices": "دستگاه بازدیدکنندگان واپسین ماه", "Last month visits": "بازدیدها واپسین ماه", "Last week orders": "سفارشات هفته پیشین", - "Latest ": "واپسین", + "Latest ": "واپسین ", "Latest products": "واپسین محصولات", "Latitude": "عرض جغرافیایی", "Link": "پیوند", @@ -251,9 +254,9 @@ "Max click": "حداکثر کلیک", "Max click zero is unlimited": "حداکثر کلیک 0 به معنای بی‌نهایت است", "Medias": "رسانه‌ها", - "Menu items": "", + "Menu items": "آیتم‌های فهرست", "Menus": "فهرست‌ها", - "Menus list": "", + "Menus list": "فهرست‌ها", "Message": "پیام", "Message replay": "پاسخ پیام", "Message...": "پیام...", @@ -278,6 +281,7 @@ "Please, Login or complete information to pay": "لطفا وارد شوید یا اطلاعات خود را تکمیل کنید تا اجازه پرداخت داشته باشید", "Post": "نوشته", "Post Text": "متن نوشته", + "Post code": "کد پستی", "Post reply": "پاسخ نوشته", "Post your comment": "دیدگاه خود را ارسال کنید", "Posts": "نوشته‌ها", @@ -382,8 +386,8 @@ "Toggle favorite": "تغییر وضعیت علاقه‌مندی", "Toggle navigation": "", "Toggle selection": "برعکس کردن انتخاب", - "Total price": "مبلغ کل", "Total": "همه", + "Total price": "مبلغ کل", "Translate": "ترجمه", "Translate model": "ترجمه ماژول", "Translate updated": "ترجمه افزوده شد", @@ -440,12 +444,14 @@ "an hour ago": "یک ساعت پیش", "approved": "تایید شد", "area :NAME of website updated": "محیط :NAME وبسایت به روز شد", + "article": "مقاله", "click here to request another": "برای ایجاد درخواست دیگر اینجا کلیک کنید", "emoji": "ایموجی", "image": "تصویر", "jpg": "", "minute": "دقیقه", "minute(s)": "دقیقه", + "news": "خبر", "not searchable": "غیرقابل جستجو", "one second ago": "یک ثانیه پیش", "password repeat": "تکرار گذرواژه", diff --git a/routes/web.php b/routes/web.php index 9cef5fb..ce65967 100644 --- a/routes/web.php +++ b/routes/web.php @@ -428,9 +428,9 @@ Route::get('whoami', function () { Route::any('{lang}/{any}', [ClientController::class, 'lang']) ->where('any', '.*') ->where('lang','[A-Za-z]{2}') - ->middleware([\App\Http\Middleware\LangControl::class]); + ->middleware([\App\Http\Middleware\LangControl::class,\App\Http\Middleware\VisitorCounter::class]); Route::any('{lang}', [ClientController::class, 'langIndex']) ->where('lang','[A-Za-z]{2}') - ->middleware([\App\Http\Middleware\LangControl::class]); + ->middleware([\App\Http\Middleware\LangControl::class,\App\Http\Middleware\VisitorCounter::class]);