mcamara / laravel-localization

Easy localization for Laravel
MIT License
3.38k stars 515 forks source link

Problem with translated routes and switching language while using localesMapping #645

Open CristianEstiber opened 5 years ago

CristianEstiber commented 5 years ago

Hello, I have mapped my locales like that:

'localesMapping' => ['es' => 'es_ES', 'en-US' => 'en_US'],

So an example of my routes would be:

http://localhost/laravel/public/es_ES/aventura http://localhost/laravel/public/en_US/adventure

this works fine except when I try to switch languages and get the route translated at the same time example:

@foreach(LaravelLocalization::getSupportedLocales() as $localeCode => $properties)
  @if(app()->getLocale() != $localeCode)
    <a rel="alternate" hreflang="{{ $localeCode }}" class="dropdown-item" href="{{LaravelLocalization::getURLFromRouteNameTranslated($localeCode, 'routes.'.Route::currentRouteName(), []) }}">$properties['regional']</a>
    @endif
@endforeach

I'm using the getURLFromRouteNameTranslated method instead of getLocalizedURL so I can have my urls translated, problem is it generates the routes without the localesMapping, something like that:

http://localhost/laravel/public/es/aventura http://localhost/laravel/public/en-US/adventure

Any way to get my localesMapping instead of the real locales?

devrushit commented 4 years ago

same issue

reganjohnson commented 4 years ago

Same issue