marciojc / language-switch by marciojc

A Laravel Package to switch language
Package Data
Maintainer Username: marciojc
Maintainer Contact: (Márcio Coelho)
Package Create Date: 2017-04-29
Package Last Update: 2017-05-01
Language: PHP
License: MIT
Last Refreshed: 2024-05-14 15:06:44
Package Statistics
Total Downloads: 13
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 1
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

Language Switch

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'