Skip to content

Commit

Permalink
Much simpler work-around
Browse files Browse the repository at this point in the history
which does not confuse "creator" and authority roles
  • Loading branch information
eronisko committed Nov 3, 2023
1 parent 3297483 commit 21911a1
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 60 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 0 additions & 39 deletions app/Authority.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions resources/views/components/authority_description.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
@if ($author->roles)
<p class="lead">
<span class="hidden"> | {{ utrans('authority.roles') }}:</span>
@foreach ($author->rolesFormatted as $role)
@foreach (collect($author->roles)->filter() as $role)
<a href="{{ route('frontend.author.index', ['role' => $role]) }}">
<strong
itemprop="{{ $author->isCorporateBody() ? 'knowsAbout' : 'jobTitle' }}">{{ $role }}</strong>
itemprop="{{ $author->isCorporateBody() ? 'knowsAbout' : 'jobTitle' }}">{{ trans_choice($role, $author->sex) }}</strong>
</a>{{ !$loop->last ? ', ' : '' }}
@endforeach
</p>
Expand Down
18 changes: 0 additions & 18 deletions tests/Models/AuthorityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 21911a1

Please sign in to comment.