Skip to content

Commit

Permalink
Display language name in content listing (#2976)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrieinv authored Mar 6, 2025
1 parent 33fb3c0 commit ffabae1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions sourcecode/hub/app/DataObjects/ContentDisplayItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function __construct(
public int $viewsCount,
public string $contentType,
public string $languageIso639_3,
public string|null $languageDisplayName,
public array|string $users,
public string|null $detailsUrl,
public string|null $previewUrl,
Expand Down
4 changes: 4 additions & 0 deletions sourcecode/hub/app/Http/Requests/ContentFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,17 @@ private function attachModel(array $hits, bool $forUser, bool $showDrafts): Coll
$canDelete = $forUser && Gate::allows('delete', $content);
$canCopy = Gate::allows('copy', $content);

$languageName = locale_get_display_language($version->language_iso_639_3, app()->getLocale());
$languageName = (!empty($languageName) && $languageName !== $version->language_iso_639_3) ? $languageName : null;

return new ContentDisplayItem(
title: $version->title,
createdAt: $version->created_at?->toImmutable(),
isPublished: $version->published,
viewsCount: $content->views_count,
contentType: $item['content_type'] ?? $version->getDisplayedContentType(),
languageIso639_3: strtoupper($version->language_iso_639_3),
languageDisplayName: $languageName,
users: $content->users->map(fn($user) => $user->name)->join(', '),
detailsUrl: $showDrafts ? route('content.version-details', [$content, $version]) : route('content.details', [$content]),
previewUrl: route('content.preview', [$content, $version]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ class="text-decoration-none link-body-emphasis"
<div class="col-auto small content-type">
{{ $content->contentType }}
</div>
<div class="col-auto badge text-bg-primary">
<div
class="col-auto badge text-bg-primary fw-normal"
@isset($content->languageDisplayName))
title="{{$content->languageDisplayName}}"
@endisset
>
{{ $content->languageIso639_3 }}
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class="col text-decoration-none link-body-emphasis"
{{ $content->users }}
</div>
<div class="col-2" aria-label="{{ trans('messages.language') }}">
{{ $content->languageIso639_3 }}
{{ $content->languageDisplayName ?: $content->languageIso639_3 }}
</div>
<div class="col-2" aria-label="{{ trans('messages.views') }}">
{{ $content->viewsCount }}
Expand Down

0 comments on commit ffabae1

Please sign in to comment.