tomatophp / filament-translations

Manage your translation with DB and cache
https://tomatophp.com/en/open-source/filament-translations
MIT License
41 stars 16 forks source link

Adding language switcher to alternative panels #10

Closed MiataBoy closed 5 months ago

MiataBoy commented 5 months ago

I was wondering if there was a simple way supported by this package to allow adding only the language switcher to other panels. I have two panels, admin where the translations are also managed, and the user dashboard panel. I seem to only be able to load the plugin on the dashboard panel with the translations management page included.

Any easy way to only load the switcher, or to deny viewing the management page / removing the management page from the sidebar?

3x1io commented 5 months ago

good idea we can try to do it on the next version.

MiataBoy commented 5 months ago

Great! In the meantime i've resolved this issue with a middleware that dynamically updates the configuration file's value depending on the panel the user is on. Definitely hope to see this in a future version.

3x1io commented 5 months ago

Use Language Switcher

You can use the language switcher in your panel by using the following plugin:

$panel->plugin(\TomatoPHP\FilamentTranslations\FilamentTranslationsPlugin::make())

NOTE Your auth user table must have lang filed on the table to make this switch work fine.

from v1.0.9

MiataBoy commented 5 months ago

Use Language Switcher

You can use the language switcher in your panel by using the following plugin:

$panel->plugin(\TomatoPHP\FilamentTranslations\FilamentTranslationsPlugin::make())

NOTE Your auth user table must have lang filed on the table to make this switch work fine.

from v1.0.9

Yes, but this also comes with the translations page. That's where the problem lies.

3x1io commented 5 months ago

Sorry

‘’’php $panel->plugin(\TomatoPHP\FilamentTranslations\FilamentTranslationsSwitcherPlugin::make()) ‘’’

MiataBoy commented 5 months ago

Yap! That adds it, unfortunately it seems actually switching doesnt work. When i switch from english to dutch, it'll reload the page but not switch the translation or change the locale in the database.

3x1io commented 5 months ago

Do you add 'lang' to your user table?

MiataBoy commented 5 months ago

Yes, the lang column was added

3x1io commented 5 months ago

can you let me see your panel provider?

MiataBoy commented 5 months ago
<?php

namespace App\Providers\Filament;

use App\Filament\Dashboard\Pages\Tenancy\EditTeamProfile;
use App\Filament\Dashboard\Pages\Tenancy\RegisterTeam;
use App\Http\Middleware\ApplyTenantScopes;
use App\Models\Team;
use Filament\Http\Middleware\Authenticate;
use Filament\Http\Middleware\DisableBladeIconComponents;
use Filament\Http\Middleware\DispatchServingFilamentEvent;
use Filament\Pages;
use Filament\Panel;
use Filament\PanelProvider;
use Filament\Support\Colors\Color;
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
use Illuminate\Cookie\Middleware\EncryptCookies;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Session\Middleware\AuthenticateSession;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\View\Middleware\ShareErrorsFromSession;

class DashboardPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->id('dashboard')
            ->path('dashboard')
            ->login()
            ->registration(env('APP_ENV') !== 'production' ? Pages\Auth\Register::class : null)
            ->profile()
            ->tenant(Team::class, ownershipRelationship: 'team', slugAttribute: 'slug')
            ->tenantRegistration(RegisterTeam::class)
            ->tenantProfile(EditTeamProfile::class)
            ->tenantMiddleware([
                ApplyTenantScopes::class,
            ], true)
            ->favicon(asset('images/favicon/favicon.ico'))
            ->colors([
                'primary' => Color::Blue,
            ])
            ->discoverResources(in: app_path('Filament/Dashboard/Resources'), for: 'App\\Filament\\Dashboard\\Resources')
            ->discoverPages(in: app_path('Filament/Dashboard/Pages'), for: 'App\\Filament\\Dashboard\\Pages')
            ->pages([
                Pages\Dashboard::class,
            ])
            ->discoverWidgets(in: app_path('Filament/Dashboard/Widgets'), for: 'App\\Filament\\Dashboard\\Widgets')
            ->widgets([
            ])

            ->plugin(\TomatoPHP\FilamentTranslations\FilamentTranslationsSwitcherPlugin::make())
            ->middleware([
                EncryptCookies::class,
                AddQueuedCookiesToResponse::class,
                StartSession::class,
                AuthenticateSession::class,
                ShareErrorsFromSession::class,
                VerifyCsrfToken::class,
                SubstituteBindings::class,
                DisableBladeIconComponents::class,
                DispatchServingFilamentEvent::class,
            ])
            ->authMiddleware([
                Authenticate::class,
            ]);
    }
}

As you can see i apply only the switcher, but the issue is there regardless of having both plugins or only the switcher, this is on version 1.0.9

AlizHarb commented 5 months ago

i have same issue with the language switcher, switching does not make any effect

3x1io commented 5 months ago

yes i found the problem and i working on fix it ASAP

3x1io commented 5 months ago

it's working now you can check the last version

https://github.com/tomatophp/filament-translations/releases/tag/v1.0.10

3x1io commented 5 months ago

@MiataBoy thanks for supporting me with your panel provider.