diff --git a/CHANGELOG.md b/CHANGELOG.md index dfe288c93..021454db6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ All notable changes to this project will be documented in this file[^1]. ## [Unreleased] ### Fixed -- redundant commas and missing CS translations for authority roles +- redundant commas from authority details ## [2.84.0] - 2023-11-02 ### Changed diff --git a/app/Authority.php b/app/Authority.php index 2d43b358c..7f71b733f 100644 --- a/app/Authority.php +++ b/app/Authority.php @@ -8,7 +8,6 @@ use Astrotomic\Translatable\Contracts\Translatable as TranslatableContract; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\File; @@ -158,44 +157,6 @@ public function getCollectionsCountAttribute() ); } - // TODO WEBUMENIA-2037 - // Workaround for missing CS translations - public function getRolesFormattedAttribute() - { - $roles = collect($this->roles); - - if (App::isLocale('en')) { - return $roles->filter(); - } - - if (App::isLocale('cs')) { - $skRoles = $this->getTranslation('sk')->roles; - $enRoles = $this->getTranslation('en')->roles; - - $reconstructedOriginalRoles = collect($skRoles) - ->zip($enRoles) - ->map(function ($pair) { - [$sk, $en] = $pair; - if ($en === null) { - return $sk; - } - return $pair->join('/'); - }); - - return $reconstructedOriginalRoles - ->map(function ($role) { - $translationKey = config("authorityRoles.{$role}"); - if ($translationKey === null) { - return null; - } - return trans($translationKey); - }) - ->filter(); - } - - return $roles->map(fn($role) => trans_choice($role, $this->sex)); - } - public function getTagsAttribute() { return Cache::remember( diff --git a/resources/views/components/authority_description.blade.php b/resources/views/components/authority_description.blade.php index 8b0a89e18..415e0f74a 100644 --- a/resources/views/components/authority_description.blade.php +++ b/resources/views/components/authority_description.blade.php @@ -34,10 +34,10 @@ @if ($author->roles)
| {{ utrans('authority.roles') }}: - @foreach ($author->rolesFormatted as $role) + @foreach (collect($author->roles)->filter() as $role) {{ $role }} + itemprop="{{ $author->isCorporateBody() ? 'knowsAbout' : 'jobTitle' }}">{{ trans_choice($role, $author->sex) }} {{ !$loop->last ? ', ' : '' }} @endforeach
diff --git a/tests/Models/AuthorityTest.php b/tests/Models/AuthorityTest.php index 702aa3983..7514e43d9 100644 --- a/tests/Models/AuthorityTest.php +++ b/tests/Models/AuthorityTest.php @@ -82,22 +82,4 @@ public function testMultipleRoles() $authority = $repository->get($authority->id); $this->assertEquals(['foo', 'bar'], $authority->roles); } - - public function testRolesFormattedWorksForAllLocales() - { - $authority = Authority::factory()->create(['sex' => 'female']); - $authority->translateOrNew('sk')->roles = ['autor', 'dizajnér']; - $authority->translateOrNew('en')->roles = ['author', null]; - $authority->translateOrNew('cs')->roles = [null, null]; - $authority->save(); - - App::setLocale('sk'); - $this->assertEquals(['autor', 'dizajnérka'], $authority->rolesFormatted->toArray()); - - App::setLocale('en'); - $this->assertEquals(['author'], $authority->rolesFormatted->toArray()); - - App::setLocale('cs'); - $this->assertEquals(['autor'], $authority->rolesFormatted->toArray()); - } }