feat: i18n string externalization with en + vi bundles

- Move every theme-rendered string (nav aria-label, theme-toggle labels, default footer template) to i18n/{lang}.toml.
- Ship en (default) + vi bundles. Adding a language is a single-file change.
- Hugo selects bundle via defaultContentLanguage (not languageCode); documented in README.
- All i18n calls have | default fallbacks so missing keys never break rendering.
This commit is contained in:
tiennm99 committed 2026-05-03 12:19:26 +07:00
1 parent 949d73c141
commit 7809c0b4c8
4 files changed
+31 -3

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
# Bonsai theme — English strings.
# Override per language by adding e.g. i18n/vi.toml; missing keys fall back to en.
[nav_links_label]
other = "Links"
[theme_toggle_label]
other = "Toggle light and dark theme"
[theme_toggle_title]
other = "Toggle theme"
[footer_default]
other = "© {{ .year }} {{ .name }}"
+13
View File
@@ -0,0 +1,13 @@
# Bonsai theme — Vietnamese strings.
[nav_links_label]
other = "Liên kết"
[theme_toggle_label]
other = "Chuyển giao diện sáng / tối"
[theme_toggle_title]
other = "Đổi giao diện"
[footer_default]
other = "© {{ .year }} {{ .name }}"
+2 -1
View File
@@ -3,7 +3,8 @@
{{- with site.Params.footerText -}}
<p>{{ . | safeHTML }}</p>
{{- else -}}
<p>© {{ now.Year }} {{ site.Params.name | default site.Title }}</p>
{{- $ctx := dict "year" now.Year "name" (site.Params.name | default site.Title) -}}
<p>{{ i18n "footer_default" $ctx | default (printf "© %d %s" now.Year (site.Params.name | default site.Title)) | safeHTML }}</p>
{{- end -}}
{{- if site.Params.themeToggle -}}
{{ partial "theme-toggle-button.html" . }}
@@ -2,9 +2,9 @@
Sun shown in dark mode (target = light). Moon shown in light mode (target = dark). */ -}}
<button type="button" class="theme-toggle"
data-bonsai-theme-toggle
aria-label="Toggle light and dark theme"
aria-label="{{ i18n "theme_toggle_label" | default "Toggle light and dark theme" }}"
aria-pressed="false"
title="Toggle theme">
title="{{ i18n "theme_toggle_title" | default "Toggle theme" }}">
<svg class="theme-toggle__sun" viewBox="0 0 24 24" width="18" height="18" aria-hidden="true">
<circle cx="12" cy="12" r="4" fill="currentColor"/>
<g stroke="currentColor" stroke-width="2" stroke-linecap="round">