Skip to content

Commit 1e10e78

Browse files
committed
fix translations
1 parent 6e3c4dd commit 1e10e78

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

packages/core/src/Entities/Items/Draft/BaseDraftResource.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,20 +186,24 @@ public static function getTitleColumn(): TextColumn
186186
return TextColumn::make('title')
187187
->label('Title')
188188
->searchable(true, function ($query, $search, $livewire) {
189-
$currentLang = $livewire->lang;
189+
$currentLang = $livewire->lang ?? request()->get('lang', app()->getLocale());
190190
$query->whereHas('translations', function ($query) use ($search, $currentLang) {
191191
$query->where('locale', $currentLang)
192192
->where('title', 'like', '%'.$search.'%');
193193
});
194194
})
195195
->sortable()
196-
->extraAttributes(fn ($record) => [
197-
'style' => $record->translations()->where('locale', request()->get('lang', app()->getLocale()))->withTrashed()->whereNotNull('title')->exists()
198-
? ''
199-
: 'color: var(--gray-500);',
200-
])
196+
->extraAttributes(function ($record, $livewire) {
197+
$currentLang = $livewire->lang ?? request()->get('lang', app()->getLocale());
198+
199+
return [
200+
'style' => $record->translations()->where('locale', $currentLang)->withTrashed()->whereNotNull('title')->exists()
201+
? ''
202+
: 'color: var(--gray-500);',
203+
];
204+
})
201205
->getStateUsing(function ($record, $livewire) {
202-
$currentLang = $livewire->lang;
206+
$currentLang = $livewire->lang ?? request()->get('lang', app()->getLocale());
203207

204208
$translation = $record->translations()->withTrashed()->where('locale', $currentLang)->first();
205209

@@ -232,7 +236,15 @@ public static function getSlugColumn(): TextColumn
232236
->where('slug', 'like', '%'.$search.'%');
233237
});
234238
})
235-
->sortable();
239+
->sortable()
240+
->getStateUsing(function ($record) {
241+
$defaultLocalization = \Moox\Localization\Models\Localization::where('is_default', true)->first();
242+
$defaultLang = $defaultLocalization?->locale_variant ?? app()->getLocale();
243+
$currentLang = request()->get('lang', $defaultLang);
244+
$translation = $record->translations()->withTrashed()->where('locale', $currentLang)->first();
245+
246+
return $translation?->slug ?? '';
247+
});
236248
}
237249

238250
public static function getTranslationStatusSelect(): Select

0 commit comments

Comments
 (0)