mcamara / laravel-localization

Easy localization for Laravel
MIT License
3.32k stars 507 forks source link

BUG: urlsIgnored doesn't work in getLocalizedURL and other methods #878

Open uacode opened 11 months ago

uacode commented 11 months ago

In cfg: 'urlsIgnored' => ['/', '/en'],

But call in tpl

@foreach(LaravelLocalization::getSupportedLocales() as $localeCode => $properties)
        <link rel="alternate" hreflang="{{ $localeCode }}" href="{{ LaravelLocalization::getLocalizedURL($localeCode, null, [], true) }}" />
    @endforeach

Generated URLs without skip route


**<link rel="alternate" hreflang="en" href="http://127.0.0.1:8000/en" />**
<link rel="alternate" hreflang="es" href="http://127.0.0.1:8000/es" />
<link rel="alternate" hreflang="fr" href="http://127.0.0.1:8000/fr" />
...
Adron55 commented 11 months ago

In laravellocalization.php there is option hideDefaultLocaleInURL. If your default language is en. It will hide it for you. 'hideDefaultLocaleInURL' => true, I had some problem when translating on language selector. I just checked if it is English. {{LaravelLocalization::getURLFromRouteNameTranslated($localeCode, 'routes.index',[],true)}} I remember getLocalizedURL didn't work correctly so I switched to routes translation in each folder
'index' => '',