0
votes

How can I edit Laravel's default login page to add a feature for lanugage change. Right now I use this package https://github.com/mcamara/laravel-localization , but the problem is it doesn't cover login form. So, right now I have something like this: http://localhost/en/userProfile, or http://localhost/de/userProfile ... But for login it is just http://localhost/login ...

In login.blade.php I have this:

<select id="changeLang">
    <option value="">{{ trans('language.languageChange') }}</option>
    <option value="/en">English</option>
    <option value="/de">Deutsch</option>
</select>

And this:

<script type="text/javascript">
    $('#changeLang').change(function (e) {
        var locAppend = $(this).find('option:selected').val(),
            locSnip = "login";
        window.location.href = locAppend + "/" + locSnip;
    });
</script>

This script reloads the page with selected language. Right now it shows an error that route is not existing. Also, I need to be able to hold selected language after login. So, when user selects english in login form, I want it to be selected for the whole application.

1

1 Answers

1
votes

in your route file make sure that Auth::routes() are prefixed with LaravelLocalization::setLocale()

Route::group([ 'prefix' => LaravelLocalization::setLocale(), 'middleware' => ['localeSessionRedirect', 'localizationRedirect']], function () {
    Route::auth();

   // other routes here
});

i suggest also to do something like this in your login blade view:

@foreach(LaravelLocalization::getSupportedLocales() as $localeCode => $properties)
   <li>
      <a rel="alternate" hreflang="{{$localeCode}}" href="{{LaravelLocalization::getLocalizedURL($localeCode) }}">
          <img class="flag" src="/assets/plugins/lang/icons/{{$localeCode}}.png" alt="" />
          {{ $properties['native'] }}
          <span class="value">{{$localeCode}}</span>
       </a>
   </li>
@endforeach