Starting to add localization into PTB

This commit is contained in:
Bruno F. Fontes 2018-09-26 22:52:43 -03:00
parent b49ec06062
commit 9a66b65f38
Signed by: brunofontes
GPG Key ID: EE3447CE80048495
8 changed files with 57 additions and 5 deletions

View File

@ -35,6 +35,7 @@ class Kernel extends HttpKernel
\Illuminate\View\Middleware\ShareErrorsFromSession::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class, \App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class, \Illuminate\Routing\Middleware\SubstituteBindings::class,
\App\Http\Middleware\Locale::class,
], ],
'api' => [ 'api' => [

View File

@ -0,0 +1,21 @@
<?php
namespace App\Http\Middleware;
use Closure;
class Locale
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
\App::setLocale(session('lang'));
return $next($request);
}
}

View File

@ -0,0 +1,12 @@
<?php
// /resources/views/home.blade.php
return [
'no_messages' => 'There are no items shared with you yet.',
'share_item' => 'Share an item!',
'return' => 'Return It',
'cancel_alert' => 'Cancel Alert',
'alert_me' => 'Alert me',
'take' => 'Take It'
];

View File

@ -0,0 +1,12 @@
<?php
// /resources/views/home.blade.php
return [
'no_messages' => 'Ainda não há itens compartilhados com você.',
'share_item' => 'Compartilhe um item!',
'return' => 'Retornar',
'cancel_alert' => 'Cancelar alerta',
'alert_me' => 'Alertar',
'take' => 'Pegar'
];

View File

@ -33,7 +33,7 @@
</div> </div>
</div> </div>
@empty @empty
<p>There are no items shared with you yet. <a href="/product">Share an item!</a></p> <p>@lang('home.no_messages')<a href="/product">@lang('home.share_item')</a></p>
@endforelse @endforelse
</div> </div>
</div> </div>

View File

@ -1,5 +1,5 @@
<form action="/take" method="POST"> <form action="/take" method="POST">
{{ csrf_field() }} {{ csrf_field() }}
<input type="hidden" name="item" value="{{$item->id}}"> <input type="hidden" name="item" value="{{$item->id}}">
<button type="submit" class="btn btn-sm btn-success">Take It</button> <button type="submit" class="btn btn-sm btn-success">@lang('home.take')</button>
</form> </form>

View File

@ -5,7 +5,7 @@
{{ csrf_field() }} {{ csrf_field() }}
@method('DELETE') @method('DELETE')
<input type="hidden" name="item" value="{{$item->id}}"> <input type="hidden" name="item" value="{{$item->id}}">
<button type="submit" class="btn btn-sm btn-danger ml-auto">Return It</button> <button type="submit" class="btn btn-sm btn-danger ml-auto">@lang('home.return')</button>
</form> </form>
@ -23,9 +23,9 @@
<input type="hidden" name="item" value="{{$item->id}}"> <input type="hidden" name="item" value="{{$item->id}}">
@if ($item->waiting_user_id == \Auth::id()) @if ($item->waiting_user_id == \Auth::id())
@method('DELETE') @method('DELETE')
<button type="submit" class="btn btn-sm btn-outline-danger ml-auto">Cancel Alert</button> <button type="submit" class="btn btn-sm btn-outline-danger ml-auto">@lang('home.cancel_alert')</button>
@elseif (!$item->waiting_user_id) @elseif (!$item->waiting_user_id)
<button type="submit" class="btn btn-sm btn-outline-secondary ml-auto">Alert me</button> <button type="submit" class="btn btn-sm btn-outline-secondary ml-auto">@lang('home.alert_me')</button>
@endif @endif
</form> </form>
@endif @endif

View File

@ -15,6 +15,12 @@ Route::get('/', function () {
return view('welcome'); return view('welcome');
}); });
Route::get('/lang/{locale}', function ($locale) {
session(['lang' => $locale]);
session()->save();
return back();
});
Route::get('/product', 'ProductController@index')->middleware('verified'); Route::get('/product', 'ProductController@index')->middleware('verified');
Route::get('/product/{product}', 'ProductController@show')->middleware('verified'); Route::get('/product/{product}', 'ProductController@show')->middleware('verified');
Route::post('/product', 'ProductController@store')->middleware('verified'); Route::post('/product', 'ProductController@store')->middleware('verified');