@php
$editLocale = $crud->getRequest()->input('_locale', app()->getLocale());
$fallbackLocale = app()->getFallbackLocale();
$translatableAttributes = $entry->getTranslatableAttributes();
$translatableLocales = $crud->model->getAvailableLocales();
$translatedLocales = [];
$translatedAttributes = array_filter($translatableAttributes, function($attribute) use ($entry, $editLocale, &$translatedLocales) {
$translation = $entry->getTranslation($attribute, $editLocale, false) ?? false;
if($translation) {
$translatedLocales[] = $editLocale;
}
return $translation;
});
$translatedLocales = array_unique($translatedLocales);
// if translated locales are empty, we need to cycle through all available locales and check if they are translated
if(empty($translatedLocales)) {
foreach ($translatableLocales as $locale => $localeName) {
if($locale === $editLocale) continue;
array_filter($translatableAttributes, function($attribute) use ($entry, $locale, &$translatedLocales) {
$translation = $entry->getTranslation($attribute, $locale, false) ?? false;
if($translation) {
$translatedLocales[] = $locale;
}
return $translation;
});
}
$translatedLocales = array_unique($translatedLocales);
}
if($crud->getOperationSetting('showTranslationNotice') === false) {
$showTranslationNotice = false;
}
$showTranslationNotice ??= empty($translatedAttributes) && ! empty($entry->getTranslatableAttributes()) && ! $crud->getRequest()->input('_fallback_locale');
if($showTranslationNotice) {
$translationNoticeText = trans('backpack::crud.no_attributes_translated', ['locale' => $translatableLocales[$editLocale]]).'
';
if(count($translatedLocales) === 1) {
$translationNoticeText .= ' > '.trans('backpack::crud.no_attributes_translated_href_text', ['locale' => $translatableLocales[current($translatedLocales)]]).'';
}else {
foreach($translatedLocales as $locale) {
$translationNoticeText .= ' > '.trans('backpack::crud.no_attributes_translated_href_text', ['locale' => $translatableLocales[$locale]]).'
';
}
}
}
@endphp