-
-
Notifications
You must be signed in to change notification settings - Fork 15
Add local columns in tables and add middleware to check and set app l… #235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
cybersoldattech
merged 15 commits into
develop
from
feature/lar-18-traduction-en-base-de-donnees
Dec 7, 2024
Merged
Changes from 4 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8cdbbaa
Add local columns in tables and add middleware to check and set app l…
cybersoldattech ea470ef
add lang flag and update middleware with livewire class
cybersoldattech 3ae3b4a
Apply lint
cybersoldattech e49ffe3
change redirection to reload event ,deleted startsession middleware i…
cybersoldattech a8e79e6
chore(deps): bump the php-dependencies group across 1 directory with …
dependabot[bot] e934196
fix:[LAR-119] fix non-existent route link and translate page
cybersoldattech 63959b7
add space in End of array, change font to font-heading
cybersoldattech 62571e2
Replace link with button
cybersoldattech 4b928e5
translate privacy page
cybersoldattech 173bc19
update migration file and add phpstan ignore line
cybersoldattech 691e489
feat: update local middleware and livewire component
mckenziearts 0beab10
Add localeScope and add translation package
cybersoldattech b763941
remove localization package and config file
cybersoldattech db2b71c
fix:[lar-18] create thread test with locale and set local app
cybersoldattech 4e91554
fix:[lar-18] apply lint
cybersoldattech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Middleware; | ||
|
||
use Closure; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
use Psr\Container\ContainerExceptionInterface; | ||
use Psr\Container\NotFoundExceptionInterface; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
final class LocaleMiddleware | ||
{ | ||
/** | ||
* @throws ContainerExceptionInterface | ||
* @throws NotFoundExceptionInterface | ||
*/ | ||
public function handle(Request $request, Closure $next): Response | ||
{ | ||
$user = Auth::user(); | ||
$lang = config('lcm.app_locale'); | ||
$supportLang = config('lcm.supported_locales'); | ||
|
||
if (! Auth::check()) { | ||
|
||
if (! is_null($request->server('HTTP_ACCEPT_LANGUAGE'))) { | ||
$navigatorLang = substr($request->server('HTTP_ACCEPT_LANGUAGE'), 0, 2); | ||
cybersoldattech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (in_array($navigatorLang, $supportLang)) { | ||
$lang = $navigatorLang; | ||
} | ||
} | ||
} | ||
|
||
if (! is_null($user)) { | ||
|
||
if (isset($user->settings['locale']) && $user->settings['locale'] != $lang) { | ||
mckenziearts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$lang = $user->settings['locale']; | ||
} | ||
} | ||
|
||
app()->setLocale($lang); | ||
|
||
return $next($request); | ||
} | ||
} |
This file contains hidden or 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,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Livewire\Components; | ||
|
||
use Illuminate\Contracts\View\View; | ||
use Illuminate\Support\Facades\Auth; | ||
use Livewire\Component; | ||
|
||
final class ChangeLocale extends Component | ||
{ | ||
public string $selectedLang; | ||
|
||
public function mount(): void | ||
{ | ||
$this->selectedLang = app()->getLocale(); | ||
} | ||
|
||
public function changeLang(string $lang): void | ||
{ | ||
$user = Auth::user(); | ||
|
||
if ($user) { | ||
$settings = $user->settings; | ||
$settings['locale'] = $lang; | ||
$user->settings = $settings; | ||
$user->save(); | ||
} | ||
|
||
app()->setLocale($lang); | ||
$this->dispatch('localeChanged'); | ||
mckenziearts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
public function render(): View | ||
{ | ||
return view('livewire.components.change-locale'); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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
29 changes: 29 additions & 0 deletions
29
database/migrations/2024_12_03_004238_add_locale_column_to_tables.php
This file contains hidden or 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,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
public function up(): void | ||
{ | ||
foreach (['articles', 'discussions', 'threads'] as $key => $value) { | ||
cybersoldattech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$afterColumn = ($key == 0) ? 'slug' : 'body'; | ||
cybersoldattech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Schema::table($value, function (Blueprint $table) use ($afterColumn): void { | ||
$table->string('locale')->default('fr')->after($afterColumn); | ||
}); | ||
} | ||
} | ||
|
||
public function down(): void | ||
{ | ||
foreach (['articles', 'discussions', 'threads'] as $tab) { | ||
Schema::table($tab, function (Blueprint $table): void { | ||
$table->dropColumn('locale'); | ||
}); | ||
} | ||
} | ||
}; |
This file contains hidden or 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
26 changes: 26 additions & 0 deletions
26
resources/views/livewire/components/change-locale.blade.php
This file contains hidden or 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,26 @@ | ||
<div class="flex space-x-2 font-heading cursor-pointer font-bold text-primary-700" x-data="{ init() { | ||
window.addEventListener('localeChanged', () => { | ||
mckenziearts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
window.location.reload(); | ||
}); | ||
} }" x-init="init()" > | ||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="flag-icons-cm" viewBox="0 0 640 480" class="w-6 h-6"> | ||
<path fill="#007a5e" d="M0 0h213.3v480H0z"/> | ||
<path fill="#ce1126" d="M213.3 0h213.4v480H213.3z"/> | ||
<path fill="#fcd116" d="M426.7 0H640v480H426.7z"/> | ||
<g fill="#fcd116" transform="translate(320 240)scale(7.1111)"> | ||
<g id="cm-b"> | ||
<path id="cm-a" d="M0-8-2.5-.4 1.3.9z"/> | ||
<use xlink:href="#cm-a" width="100%" height="100%" transform="scale(-1 1)"/> | ||
</g> | ||
<use xlink:href="#cm-b" width="100%" height="100%" transform="rotate(72)"/> | ||
<use xlink:href="#cm-b" width="100%" height="100%" transform="rotate(144)"/> | ||
<use xlink:href="#cm-b" width="100%" height="100%" transform="rotate(-144)"/> | ||
<use xlink:href="#cm-b" width="100%" height="100%" transform="rotate(-72)"/> | ||
</g> | ||
</svg> | ||
@if($selectedLang == 'fr') | ||
<button wire:click="changeLang('en')">EN</button> | ||
@else | ||
<button wire:click="changeLang('fr')">FR</button> | ||
@endif | ||
</div> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.