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:
Ümit Tunç
2025-12-31 23:35:42 +03:00
parent 009d1cbb76
commit 1fa194260e
10 changed files with 779 additions and 372 deletions
+2 -1
View File
@@ -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 ?? [];
+15 -1
View File
@@ -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;
}
/**