Gonçalo Rodrigues 4b7c01e632 feat(finance): i18n — TOML-based translations for all personal finance templates
Adds a full translation layer (English + European Portuguese) using
BurntSushi/toml with go:embed. Locale detection reads the lang cookie,
falls back to Accept-Language, then defaults to "en". A language switcher
in the nav writes the cookie and redirects back. All 20 personal finance
templates now use {{.T.Get "key"}} for every UI string.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-17 22:32:49 +01:00

88 lines
3.1 KiB
HTML

{{define "content"}}
{{$d := .}}
<h1 style="margin-bottom:24px;">{{$d.T.Get "reports.title"}}</h1>
<div class="card animate-on-scroll">
<h2>{{$d.T.Get "reports.chart_title"}}</h2>
<div style="padding-top:8px;">
<canvas id="reportChart" height="280"></canvas>
</div>
</div>
<div class="card animate-on-scroll" style="overflow-x:auto;">
<h2 style="margin-bottom:14px;">{{$d.T.Get "reports.table_title"}}</h2>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>{{$d.T.Get "reports.col_month"}}</th>
{{range $cat, $_ := $d.CategoryNames}}
{{$color := index $d.CategoryColors $cat}}
<th class="text-right" style="white-space:nowrap;">
{{if $color}}<span style="display:inline-block;width:7px;height:7px;border-radius:50%;background:{{$color}};margin-right:4px;vertical-align:middle;box-shadow:0 0 4px {{$color}}88;"></span>{{end}}{{$cat}}
</th>
{{end}}
<th class="text-right">{{$d.T.Get "reports.col_total"}}</th>
</tr>
</thead>
<tbody>
{{range $row := $d.MonthlyData}}
{{$total := sub 0 0}}
{{range $_, $v := $row.Totals}}{{$total = add $total $v}}{{end}}
<tr>
<td style="font-weight:600; white-space:nowrap;">{{$row.Month}}</td>
{{range $cat, $_ := $d.CategoryNames}}
{{$v := index $row.Totals $cat}}
<td class="cents">
{{if $v}}<span class="{{if lt $v 0}}negative{{else}}positive{{end}}">€{{cents $v}}</span>{{else}}<span class="text-muted"></span>{{end}}
</td>
{{end}}
<td class="cents" style="font-weight:600;">
<span class="{{if lt $total 0}}negative{{else}}positive{{end}}">€{{cents $total}}</span>
</td>
</tr>
{{end}}
</tbody>
</table>
</div>
</div>
<script>
const isDark = () => document.documentElement.getAttribute('data-theme') === 'dark';
const gridC = () => isDark() ? 'rgba(255,255,255,0.05)' : 'rgba(0,0,0,0.06)';
const textC = () => isDark() ? '#5c6585' : '#8a92b0';
new Chart(document.getElementById('reportChart'), {
type: 'bar',
data: {
labels: [{{range $d.MonthlyData}}"{{.Month}}",{{end}}],
datasets: [
{{$colors := $d.CategoryColors}}
{{range $cat, $_ := $d.CategoryNames}}
{
label: '{{$cat}}',
data: [{{range $d.MonthlyData}}{{$v := index .Totals $cat}}{{if $v}}{{abs $v | div 100}}{{else}}0{{end}},{{end}}],
backgroundColor: '{{index $colors $cat}}cc',
borderColor: '{{index $colors $cat}}',
borderWidth: 0,
borderRadius: 3,
},
{{end}}
]
},
options: {
responsive: true,
animation: { duration: 900, easing: 'easeOutQuart' },
plugins: {
legend: { position: 'bottom', labels: { boxWidth: 11, padding: 14, color: textC(), usePointStyle: true, pointStyle: 'circle' } },
tooltip: { mode: 'index', intersect: false }
},
scales: {
x: { stacked: true, grid: { display: false }, ticks: { color: textC() } },
y: { stacked: true, beginAtZero: true, grid: { color: gridC() }, ticks: { color: textC(), callback: v => '€' + v } }
}
}
});
</script>
{{end}}