mcamara / laravel-localization

Easy localization for Laravel
MIT License
3.35k stars 508 forks source link

Working with Laravel Nova #617

Open covaberjon opened 5 years ago

covaberjon commented 5 years ago

First of all, thank you for the package.

I have a problem using your package with Laravel Nova. I am only using your package with my frontend routes. However, my laravel nova backend is being affected.

Instead of showing my ES translations, is showing EN translations.

I tried adding:

'urlsIgnored' => ['/nova/*']

But it didn't work.

The only thing that actually worked was setting useAcceptLanguageHeader to false.

YannikFirre commented 5 years ago

Same problem caused by "LaravelLocalization::setLocale()" in ->prefix(LaravelLocalization::setLocale())

maherelgamil commented 4 years ago

Any updates here ?

marijoo commented 4 years ago

Any updates?

iwasherefirst2 commented 4 years ago

Sorry but Laravel Nova is not open source, so I can't look into it to help you. You may need to fix it by yourself and send a PR. Or switch to an open source admin panel: https://voyager.devdojo.com/

gavinhewitt commented 4 years ago

Maybe I don't understand but can't you just create a 'frontend' middlewaregroup and reference that wherever you need route localization? That's what I do. Using a seperate group for frontend does not affect any Nova routes.

ysfkaya commented 4 years ago

I have solved this issue for me. I have created a helper function for routing with using LaravelLocalization class. Try this in web.php instead of transRoute method. Add the nova paths in config file btw.

function __route($name)
{
    $shouldIgnore = function ($request) {
        $excepts = config('laravellocalization.urlsIgnored', []);

        foreach ($excepts as $except) {
            if ($except !== '/') {
                $except = trim($except, '/');
            }

            if ($request->is($except)) {
                return true;
            }
        }

        return false;
    };

    if ($shouldIgnore(request())) {
        return;
    }

    return LaravelLocalization::transRoute('routes.' . $name);
}
namnh06 commented 3 years ago

@ysfkaya no luck man :(.