Skip to content

Commit

Permalink
ADD support to multiple languages from config/app.php config file
Browse files Browse the repository at this point in the history
  • Loading branch information
Webunion committed Nov 29, 2015
1 parent 8cbbe31 commit a648f3f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
3 changes: 2 additions & 1 deletion app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public function index()
public function language( $lang = false,
ChangeLocale $changeLocale)
{
$lang = $lang ?: config('app.fallback_locale');

$lang = in_array($lang, config('app.languages')) ? $lang : config('app.fallback_locale');
$changeLocale->lang = $lang;
$this->dispatch($changeLocale);

Expand Down
15 changes: 14 additions & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,20 @@
|
*/

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

/*
|--------------------------------------------------------------------------
| Application avaiable Languages
|--------------------------------------------------------------------------
|
| A list off avaiable languages defined from their ISO codes, see more: https://en.wikipedia.org/wiki/ISO_3166-1.
| If the code isn't on the list, HomeController@language will set from fallback_locale value.
! To set new languages, pelase create an folder in /resources/lang/{ISO-CODE}, create a flag image in public/img/{ISO-CODE}-flang.png
! and at least, add the ISO code in languages array.
*/

'languages' => ['en', 'fr', 'br'],

/*
|--------------------------------------------------------------------------
Expand Down
8 changes: 3 additions & 5 deletions resources/views/front/template.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,9 @@
<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>
@foreach ( config('app.languages') as $user)
<li><a href="{!! url('language') !!}/{{ $user }}"><img width="32" height="32" alt="{{ $user }}" src="{!! asset('img/' . $user . '-flag.png') !!}"></a></li>
@endforeach
</ul>
</li>
</ul>
Expand Down

0 comments on commit a648f3f

Please sign in to comment.