From 7aa510e1f553c9e0032803c816f695d23bb056e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Rodrigues?= Date: Wed, 17 Jun 2026 22:49:54 +0100 Subject: [PATCH] =?UTF-8?q?fix(finance):=20i18n=20=E2=80=94=20fix=20TOML?= =?UTF-8?q?=20duplicate=20key=20and=20missing=20Lang=20on=20Translator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove conflicting `analysis = "..."` scalar from [nav] in both en.toml and pt.toml; it shadowed the [nav.analysis] sub-table, causing the TOML parser to reject the entire file at startup - Update nav analysis dropdown label to reuse nav.drawer.analysis_label - Add lang field to Translator and expose T.Lang() method so base.html can highlight the active language in the switcher without requiring a Lang field on every page data struct Co-Authored-By: Claude Sonnet 4.6 --- apps/finance/services/api/main/i18n.go | 13 ++++++++++--- apps/finance/services/api/main/locales/en.toml | 1 - apps/finance/services/api/main/locales/pt.toml | 1 - apps/finance/services/api/main/templates/base.html | 6 +++--- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/apps/finance/services/api/main/i18n.go b/apps/finance/services/api/main/i18n.go index bf717f6..953ad17 100644 --- a/apps/finance/services/api/main/i18n.go +++ b/apps/finance/services/api/main/i18n.go @@ -65,8 +65,9 @@ func flattenTOML(prefix string, node map[string]any, out catalogue) { // Translator wraps a locale lookup and exposes a Get method callable from // Go templates as {{.T.Get "key"}}. type Translator struct { - cat catalogue - en catalogue + lang string + cat catalogue + en catalogue } func (tr *Translator) Get(key string) string { @@ -79,13 +80,19 @@ func (tr *Translator) Get(key string) string { return key } +// Lang returns the active language code for use in templates (e.g. {{.T.Lang}}). +func (tr *Translator) Lang() string { + return tr.lang +} + // newT returns a Translator for the given language. func newT(lang string) *Translator { cat, ok := catalogues[lang] if !ok { + lang = defaultLang cat = catalogues[defaultLang] } - return &Translator{cat: cat, en: catalogues[defaultLang]} + return &Translator{lang: lang, cat: cat, en: catalogues[defaultLang]} } // detectLang reads the lang from a cookie, falling back to Accept-Language, diff --git a/apps/finance/services/api/main/locales/en.toml b/apps/finance/services/api/main/locales/en.toml index ed40023..1573f53 100644 --- a/apps/finance/services/api/main/locales/en.toml +++ b/apps/finance/services/api/main/locales/en.toml @@ -8,7 +8,6 @@ portfolio = "Portfolio" goals = "Goals" property = "Property" people = "People" -analysis = "Analysis" settings = "Settings" business = "🏢 Business" hub_back = "← Hub" diff --git a/apps/finance/services/api/main/locales/pt.toml b/apps/finance/services/api/main/locales/pt.toml index 6c6a47f..eac5426 100644 --- a/apps/finance/services/api/main/locales/pt.toml +++ b/apps/finance/services/api/main/locales/pt.toml @@ -8,7 +8,6 @@ portfolio = "Carteira" goals = "Objetivos" property = "Imóveis" people = "Pessoas" -analysis = "Análise" settings = "Definições" business = "🏢 Empresa" hub_back = "← Hub" diff --git a/apps/finance/services/api/main/templates/base.html b/apps/finance/services/api/main/templates/base.html index 4d61c35..3c43fee 100644 --- a/apps/finance/services/api/main/templates/base.html +++ b/apps/finance/services/api/main/templates/base.html @@ -584,7 +584,7 @@ {{$analysisActive := or (eq .Route "reports") (eq .Route "projections") (eq .Route "networth") (eq .Route "simulator") (eq .Route "tax")}}