Refactor Localization in Templates: Updated various templates to utilize the translation function for titles and content, enhancing localization support. Commented out unused fallback logic in the PageController for header templates, streamlining the rendering process. Added new header and navbar components while removing the deprecated navbar file, improving the overall structure and maintainability of the layout.
This commit is contained in:
@@ -43,10 +43,11 @@ class PageController extends Controller
|
||||
|
||||
// Header Render
|
||||
$headerTemplate = $page->headerTemplate;
|
||||
/*
|
||||
if (!$headerTemplate) {
|
||||
$headerTemplate = HeaderTemplate::where('is_active', true)->latest('updated_at')->first();
|
||||
}
|
||||
|
||||
*/
|
||||
if ($headerTemplate) {
|
||||
$templateDefaults = $headerTemplate->default_data ?? [];
|
||||
$pageData = $page->header_data ?? [];
|
||||
|
||||
@@ -57,7 +57,21 @@ trait HasTranslations
|
||||
}
|
||||
|
||||
// Fallback to original field value
|
||||
return $this->{$fieldName} ?? null;
|
||||
$originalValue = $this->{$fieldName} ?? null;
|
||||
|
||||
// If the original value is an array (e.g. JSON cast), try to find translation inside it
|
||||
if (is_array($originalValue)) {
|
||||
if (isset($originalValue[$languageCode])) {
|
||||
return $originalValue[$languageCode];
|
||||
}
|
||||
if ($fallback && isset($originalValue[$this->getDefaultLanguageCode()])) {
|
||||
return $originalValue[$this->getDefaultLanguageCode()];
|
||||
}
|
||||
// Return first value if available, or empty string
|
||||
return reset($originalValue) ?: '';
|
||||
}
|
||||
|
||||
return $originalValue;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user