1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-16 16:13:20 +01:00
invoiceninja/app/Http/Middleware/VendorLocale.php

95 lines
2.5 KiB
PHP
Raw Normal View History

2022-06-13 11:59:24 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2024-04-12 06:15:41 +02:00
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
2022-06-13 11:59:24 +02:00
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
class VendorLocale
{
2023-11-26 08:41:42 +01:00
private array $locales = [
'en',
'it',
'de',
'fr',
'pt_BR',
'nl',
'es',
'nb_NO',
'da',
'ja',
'sv',
'es_ES',
'fr_CA',
'lt',
'pl',
'cs',
'hr',
'sq',
'el',
'en_GB',
'pt_PT',
'sl',
'fi',
'ro',
'tr_TR',
'th',
'mk_MK',
'zh_TW',
'ru_RU',
'ar',
'fa',
'lv_LV',
'sr',
'sk',
'et',
'bg',
'he',
'km_KH',
'hu',
'fr_CH',
2024-01-12 11:04:54 +01:00
'lo_LA',
2023-11-26 08:41:42 +01:00
];
2022-06-13 11:59:24 +02:00
/**
* Handle an incoming request.
*
* @param Request $request
* @param Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
2022-06-15 13:24:30 +02:00
if (auth()->guard('contact')->check()) {
auth()->guard('contact')->logout();
$request->session()->invalidate();
}
2022-06-13 11:59:24 +02:00
/*LOCALE SET */
2023-11-26 08:41:42 +01:00
if ($request->has('lang') && in_array($request->input('lang', 'en'), $this->locales)) {
2022-06-13 11:59:24 +02:00
$locale = $request->input('lang');
App::setLocale($locale);
} elseif (auth()->guard('vendor')->user()) {
2023-08-10 02:56:34 +02:00
App::setLocale(auth()->guard('vendor')->user()->vendor->locale());
2022-06-13 11:59:24 +02:00
} elseif (auth()->user()) {
try {
2022-06-13 11:59:24 +02:00
App::setLocale(auth()->user()->company()->getLocale());
} catch (\Exception $e) {
2022-06-13 11:59:24 +02:00
}
} else {
App::setLocale(config('ninja.i18n.locale'));
}
return $next($request);
}
}