forked from HiEventsDev/Hi.Events
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a3e97ef
commit 831164f
Showing
79 changed files
with
2,942 additions
and
568 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace HiEvents\Http\Middleware; | ||
|
||
use Closure; | ||
use HiEvents\DomainObjects\UserDomainObject; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\App; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class SetUserLocaleMiddleware | ||
{ | ||
public function handle(Request $request, Closure $next) | ||
{ | ||
if (Auth::check()) { | ||
/** @var UserDomainObject $user */ | ||
$user = UserDomainObject::hydrateFromModel(Auth::user()); | ||
App::setLocale($user->getLocale()); | ||
App::setFallbackLocale(config('app.locale')); | ||
} elseif ($request->hasHeader('Accept-Language')) { | ||
App::setLocale($request->header('Accept-Language')); | ||
App::setFallbackLocale(config('app.locale')); | ||
} | ||
|
||
return $next($request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace HiEvents; | ||
|
||
use HiEvents\DomainObjects\Enums\BaseEnum; | ||
|
||
enum Locale: string | ||
{ | ||
use BaseEnum; | ||
|
||
case EN = 'en'; | ||
case DE = 'de'; | ||
case FR = 'fr'; | ||
case ES = 'es'; | ||
case PT = 'pt'; | ||
case PT_BR = 'pt-br'; | ||
case ZH_CN = 'zh-cn'; | ||
|
||
public static function getSupportedLocales(): array | ||
{ | ||
return self::valuesArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace HiEvents\Services\Application\Locale; | ||
|
||
use HiEvents\Locale; | ||
use Illuminate\Config\Repository; | ||
|
||
class LocaleService | ||
{ | ||
public function __construct( | ||
private readonly Repository $config, | ||
) | ||
{ | ||
} | ||
|
||
public function getLocaleOrDefault(string $locale): string | ||
{ | ||
$supportedLocales = Locale::getSupportedLocales(); | ||
|
||
if (in_array($locale, $supportedLocales, true)) { | ||
return $locale; | ||
} | ||
|
||
$normalizedLocale = str_replace('_', '-', $locale); | ||
$baseLanguage = explode('-', $normalizedLocale)[0]; | ||
|
||
foreach ($supportedLocales as $supportedLocale) { | ||
if (str_starts_with($supportedLocale, $baseLanguage)) { | ||
return $supportedLocale; | ||
} | ||
} | ||
|
||
return $this->config->get('app.locale'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.