feat: implement real-time SEO character counters and improve default avatar handling and translation logic.
This commit is contained in:
@@ -45,14 +45,14 @@ trait HasTranslations
|
||||
// 1. Try translations table
|
||||
$translation = $this->getTranslation($fieldName, $languageCode);
|
||||
|
||||
if ($translation && !empty($translation->field_value)) {
|
||||
if ($translation && $this->hasValidTranslationContent($translation->field_value)) {
|
||||
return $translation->field_value;
|
||||
}
|
||||
|
||||
// 2. Fallback to default language from translations table
|
||||
if ($fallback && $languageCode !== $this->getDefaultLanguageCode()) {
|
||||
$defaultTranslation = $this->getTranslation($fieldName, $this->getDefaultLanguageCode());
|
||||
if ($defaultTranslation && !empty($defaultTranslation->field_value)) {
|
||||
if ($defaultTranslation && $this->hasValidTranslationContent($defaultTranslation->field_value)) {
|
||||
return $defaultTranslation->field_value;
|
||||
}
|
||||
}
|
||||
@@ -267,6 +267,23 @@ trait HasTranslations
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if translation content has meaningful text or media
|
||||
*/
|
||||
protected function hasValidTranslationContent(mixed $value): bool
|
||||
{
|
||||
if (empty($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_string($value)) {
|
||||
$stripped = trim(strip_tags($value, '<img><iframe><video><audio>'));
|
||||
return $stripped !== '';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get translatable fields for this model
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user