From 3f8073e55230532f4e9b55dd7e1bdfcb68b451f8 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Wed, 20 Dec 2017 13:27:57 -0600 Subject: [PATCH] Add initial translations for enumerated values --- app/Models/Enums/Days.php | 14 ++++++------- app/Models/Enums/EnumBase.php | 6 +++++- app/Models/Enums/PirepState.php | 8 +++---- config/app.php | 1 + resources/lang/en/system.php | 21 +++++++++++++++++++ .../layouts/default/pireps/show.blade.php | 12 +++++++---- 6 files changed, 46 insertions(+), 16 deletions(-) create mode 100644 resources/lang/en/system.php diff --git a/app/Models/Enums/Days.php b/app/Models/Enums/Days.php index 54300c99..b1bec568 100644 --- a/app/Models/Enums/Days.php +++ b/app/Models/Enums/Days.php @@ -17,12 +17,12 @@ class Days extends EnumBase { const SUNDAY = 64; protected static $labels = [ - Days::MONDAY => 'Monday', - Days::TUESDAY => 'Tuesday', - Days::WEDNESDAY => 'Wednesday', - Days::THURSDAY => 'Thursday', - Days::FRIDAY => 'Friday', - Days::SATURDAY => 'Saturday', - Days::SUNDAY => 'Sunday', + Days::MONDAY => 'system.days.mon', + Days::TUESDAY => 'system.days.tues', + Days::WEDNESDAY => 'system.days.wed', + Days::THURSDAY => 'system.days.thurs', + Days::FRIDAY => 'system.days.fri', + Days::SATURDAY => 'system.days.sat', + Days::SUNDAY => 'system.days.sun', ]; } diff --git a/app/Models/Enums/EnumBase.php b/app/Models/Enums/EnumBase.php index 436c3dbb..0f4c0e27 100644 --- a/app/Models/Enums/EnumBase.php +++ b/app/Models/Enums/EnumBase.php @@ -17,12 +17,16 @@ namespace App\Models\Enums; class EnumBase { protected static $labels = []; + protected static $adverbs = []; /** + * Return the label, try to return the translated version as well * @param $value * @return mixed */ public static function label($value) { - return self::$labels[$value]; + if(isset(static::$labels[$value])) { + return trans(static::$labels[$value]); + } } } diff --git a/app/Models/Enums/PirepState.php b/app/Models/Enums/PirepState.php index 1711fd72..8da5bc6a 100644 --- a/app/Models/Enums/PirepState.php +++ b/app/Models/Enums/PirepState.php @@ -2,16 +2,16 @@ namespace App\Models\Enums; -use Illuminate\Support\Facades\Facade; class PirepState extends EnumBase { + const REJECTED = -1; const PENDING = 0; const ACCEPTED = 1; protected static $labels = [ - PirepState::REJECTED => 'Rejected', - PirepState::PENDING => 'Pending', - PirepState::ACCEPTED => 'Accepted', + PirepState::REJECTED => 'system.pireps.state.rejected', + PirepState::PENDING => 'system.pireps.state.pending', + PirepState::ACCEPTED => 'system.pireps.state.accepted', ]; } diff --git a/config/app.php b/config/app.php index 3cd8671e..ea490a7c 100755 --- a/config/app.php +++ b/config/app.php @@ -119,6 +119,7 @@ return [ # ENUMS + 'PirepSource' => App\Models\Enums\PirepSource::class, 'PirepState' => App\Models\Enums\PirepState::class, 'PirepStatus' => App\Models\Enums\PirepStatus::class, ], diff --git a/resources/lang/en/system.php b/resources/lang/en/system.php new file mode 100644 index 00000000..e34ccafd --- /dev/null +++ b/resources/lang/en/system.php @@ -0,0 +1,21 @@ + [ + 'mon' => 'Monday', + 'tues' => 'Tuesday', + 'wed' => 'Wednesday', + 'thurs' => 'Thursday', + 'fri' => 'Friday', + 'sat' => 'Saturday', + 'sun' => 'Sunday', + ], + + 'pireps' => [ + 'state' => [ + 'accepted' => 'Accepted', + 'pending' => 'Pending', + 'rejected' => 'Rejected', + ], + ], +]; diff --git a/resources/views/layouts/default/pireps/show.blade.php b/resources/views/layouts/default/pireps/show.blade.php index 8be5ff86..d61c4815 100644 --- a/resources/views/layouts/default/pireps/show.blade.php +++ b/resources/views/layouts/default/pireps/show.blade.php @@ -14,13 +14,17 @@ Status - @if($pirep->state == PirepState::PENDING) -
Pending
+ @if($pirep->state === PirepState::PENDING) +
{!! PirepState::label(PirepState::PENDING) !!}
@elseif($pirep->state === PirepState::ACCEPTED) -
Accepted
+
{!! PirepState::label(PirepState::ACCEPTED) !!}
@else -
Rejected
+
{!! PirepState::label(PirepState::REJECTED) !!}
@endif + + + source: {!! PirepSource::label($pirep->source) !!} +