Skip to content

Commit

Permalink
Add localization for days asantibanez#30, event count asantibanez#29
Browse files Browse the repository at this point in the history
…and "No description"
  • Loading branch information
skeemer committed Aug 5, 2023
1 parent ac8abbb commit 015f7bd
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 5 deletions.
4 changes: 2 additions & 2 deletions resources/views/day-of-week.blade.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div class="flex-1 h-12 border -mt-px -ml-px flex items-center justify-center bg-indigo-100 text-gray-900"
style="min-width: 10rem;">

<p class="text-sm">
{{ $day->format('l') }}
<p class="text-sm day-of-week">
{{ $day->locale(app()->getLocale())->isoFormat('dddd') }}
</p>

</div>
2 changes: 1 addition & 1 deletion resources/views/day.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class="w-full h-full p-2 {{ $dayInMonth ? $isToday ? 'bg-yellow-100' : ' bg-whit
</p>
<p class="text-xs text-gray-600 ml-4">
@if($events->isNotEmpty())
{{ $events->count() }} {{ Str::plural('event', $events->count()) }}
{{ $events->count() }} {{ __(Str::plural('event', $events->count())) }}
@endif
</p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/event.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class="bg-white rounded-lg border py-2 px-3 shadow-md cursor-pointer">
{{ $event['title'] }}
</p>
<p class="mt-2 text-xs">
{{ $event['description'] ?? 'No description' }}
{{ $event['description'] ?? __('No description') }}
</p>
</div>
21 changes: 20 additions & 1 deletion tests/Support/LivewireCalendarTestComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@ class LivewireCalendarTestComponent extends LivewireCalendar
{
public function events(): Collection
{
return collect();
return collect([
[
'id' => 1,
'title' => 'Breakfast',
'description' => 'Pancakes! 🥞',
'date' => now()->startOfMonth(),
],
[
'id' => 2,
'title' => 'Meeting with Pamela',
'description' => 'Work stuff',
'date' => now()->startOfMonth(),
],
[
'id' => 2,
'title' => 'Meeting with Frank',
'description' => null,
'date' => now()->startOfMonth()->addDay(),
],
]);
}
}
53 changes: 53 additions & 0 deletions tests/ViewLocalization.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace LittleSaneVillage\LivewireCalendar\Tests;

use LittleSaneVillage\LivewireCalendar\Tests\Support\LivewireCalendarTestComponent;
use Livewire\Livewire;

class ViewLocalization extends TestCase
{
public function testDayOfWeekLocalization(): void
{
app()->setLocale('en');
Livewire::test(LivewireCalendarTestComponent::class)
->assertSeeText('Monday')
->assertDontSeeText('понеділок');
app()->setLocale('uk');
Livewire::test(LivewireCalendarTestComponent::class)
->assertDontSeeText('Monday')
->assertSeeText('понеділок');
}

public function testEventsLocalization(): void
{
/** @var \Illuminate\Translation\Translator $translator */
$translator = app('translator');
$translator->addLines(['*.event' => 'подія', '*.events' => 'події'], 'uk');

app()->setLocale('en');
Livewire::test(LivewireCalendarTestComponent::class)
->assertSeeText('1 event')
->assertSeeText('2 events');

app()->setLocale('uk');
Livewire::test(LivewireCalendarTestComponent::class)
->assertSeeText('1 подія')
->assertSeeText('2 події');
}

public function testNoDescriptionLocalization(): void
{
/** @var \Illuminate\Translation\Translator $translator */
$translator = app('translator');
$translator->addLines(['*.No description' => 'без опису'], 'uk');

app()->setLocale('en');
Livewire::test(LivewireCalendarTestComponent::class)
->assertSeeText('No description');

app()->setLocale('uk');
Livewire::test(LivewireCalendarTestComponent::class)
->assertSeeText('без опису');
}
}

0 comments on commit 015f7bd

Please sign in to comment.