From 48aab974fed0dd3861e746440a21f0e430b73906 Mon Sep 17 00:00:00 2001 From: logikonline Date: Wed, 18 Mar 2026 00:05:05 -0400 Subject: [PATCH] fix(pages): populate defaults before translation overlay Add ensureTemplateDefaults function that fills navigation labels and section headlines with template-specific defaults before applying translation overlay. Ensures these fields are present in base config JSON so translations can override them via deep-merge. Fixes issue where translated labels wouldn't apply because base config had empty strings instead of default values. Prevents templates from falling back to hardcoded English text. --- routers/web/pages/pages.go | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/routers/web/pages/pages.go b/routers/web/pages/pages.go index 062eb9633a..095d3c3f3a 100644 --- a/routers/web/pages/pages.go +++ b/routers/web/pages/pages.go @@ -1174,6 +1174,11 @@ func detectPageLanguage(ctx *context.Context, config *pages_module.LandingConfig // applyLanguageOverlay loads the translation for the detected language and merges it onto config. // Sets template data for the language switcher and returns the (possibly merged) config. func applyLanguageOverlay(ctx *context.Context, repo *repo_model.Repository, config *pages_module.LandingConfig) *pages_module.LandingConfig { + // Ensure navigation labels and section headlines are populated with + // template-specific defaults so they are present in the base config + // for deep-merge (and so templates never fall back to hardcoded English). + ensureTemplateDefaults(config) + if len(config.I18n.Languages) == 0 { return config } @@ -1215,6 +1220,44 @@ func applyLanguageOverlay(ctx *context.Context, repo *repo_model.Repository, con return merged } +// ensureTemplateDefaults fills in empty navigation labels and section headlines +// with template-specific defaults so they are always present for serialization +// and deep-merge. This ensures the base config JSON contains these keys, making +// them available for the translation overlay to override. +func ensureTemplateDefaults(config *pages_module.LandingConfig) { + defaults := pages_module.TemplateDefaultLabels(config.Template) + nav := &config.Navigation + if nav.LabelValueProps == "" { + nav.LabelValueProps = defaults.LabelValueProps + } + if nav.LabelFeatures == "" { + nav.LabelFeatures = defaults.LabelFeatures + } + if nav.LabelPricing == "" { + nav.LabelPricing = defaults.LabelPricing + } + if nav.LabelBlog == "" { + nav.LabelBlog = defaults.LabelBlog + } + if nav.LabelGallery == "" { + nav.LabelGallery = defaults.LabelGallery + } + if nav.LabelCompare == "" { + nav.LabelCompare = defaults.LabelCompare + } + // Section headlines — fill empty headlines with sensible defaults + // so they appear in the base JSON and can be overridden by translations. + if config.Blog.Enabled && config.Blog.Headline == "" { + config.Blog.Headline = "Latest Posts" + } + if config.Gallery.Enabled && config.Gallery.Headline == "" { + config.Gallery.Headline = "Gallery" + } + if config.Comparison.Enabled && config.Comparison.Headline == "" { + config.Comparison.Headline = "How We Compare" + } +} + // ApproveExperiment handles the email approval link for an A/B test experiment func ApproveExperiment(ctx *context.Context) { handleExperimentAction(ctx, true)