Skip to content

Commit

Permalink
ADD support for multiple languages
Browse files Browse the repository at this point in the history
  • Loading branch information
Webunion committed Nov 29, 2015
1 parent 47eca6d commit eb66a22
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 6 deletions.
4 changes: 3 additions & 1 deletion app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ public function index()
* @param App\Jobs\ChangeLocaleCommand $changeLocaleCommand
* @return Response
*/
public function language(
public function language( $lang = false,
ChangeLocale $changeLocale)
{
$lang = $lang ?: config('app.fallback_locale');
$changeLocale->lang = $lang;
$this->dispatch($changeLocale);

return redirect()->back();
Expand Down
2 changes: 1 addition & 1 deletion app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'uses' => 'HomeController@index',
'as' => 'home'
]);
Route::get('language', 'HomeController@language');
Route::get('language/{lang}', 'HomeController@language');


// Admin
Expand Down
4 changes: 3 additions & 1 deletion app/Jobs/ChangeLocale.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

class ChangeLocale extends Job implements SelfHandling
{
public $lang;

/**
* Execute the job.
*
* @return void
*/
public function handle()
{
session()->set('locale', session('locale') == 'fr' ? 'en' : 'fr');
session()->set('locale', $this->lang);
}
}
2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
|
*/

'locale' => 'en',
'locale' => 'pt-BR',

/*
|--------------------------------------------------------------------------
Expand Down
Binary file removed public/img/english-flag.png
Binary file not shown.
Binary file removed public/img/french-flag.png
Binary file not shown.
11 changes: 9 additions & 2 deletions resources/views/front/template.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,15 @@
</li>
@endif
@endif
<li class="imgflag">
<a href="{!! url('language') !!}"><img width="32" height="32" alt="en" src="{!! asset('img/' . (session('locale') == 'fr' ? 'english' : 'french') . '-flag.png') !!}"></a>
<li class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle" href="#"><img width="32" height="32" alt="{{ session('locale') }}" src="{!! asset('img/' . session('locale') . '-flag.png') !!}" />&nbsp; <b class="caret"></b></a>
<ul class="dropdown-menu">
<li>
<a href="{!! url('language') !!}/fr"><img width="32" height="32" alt="en" src="{!! asset('img/fr-flag.png') !!}"></a>
<a href="{!! url('language') !!}/en"><img width="32" height="32" alt="en" src="{!! asset('img/en-flag.png') !!}"></a>
<a href="{!! url('language') !!}/br"><img width="32" height="32" alt="br" src="{!! asset('img/br-flag.png') !!}"></a>
</li>
</ul>
</li>
</ul>
</div>
Expand Down

0 comments on commit eb66a22

Please sign in to comment.