A Laravel Package to switch language

1.0.0 2017-04-29 22:57 UTC

This package is not auto-updated.

Last update: 2024-06-06 05:27:45 UTC


Website & Documentation:

After creating your new Laravel application you can include the LanguageSwitch package with the following command:

composer require marciojc/language-switch

Add the LanguageSwitch service provider to the config/app.php file in the providers array:

'providers' => [
    // Laravel Framework Service Providers...

    // Package Service Providers
    // ...

    // Application Service Providers
    // ...

Now, you can use LanguageSwitch, like this

<div class="language">
  @if (App::getLocale() == 'pt')
    <a class="lang-link" href="{{getTranslationUrl('en')}}">{{ trans('common.en') }}</a>
    <a class="lang-link" href="{{getTranslationUrl('pt')}}">{{ trans('') }}</a>

When your route use some id or slug, you must say what model to use

Route::get(trans('') . '/{slug}' , [
  'as'           => 'newsdetails',
  'uses'         => 'NewsController@details',
  'model'        => 'App\News'