From 7809c0b4c8a9cc1b7d4b27a33866a85139f5c166 Mon Sep 17 00:00:00 2001 From: tiennm99 Date: Sun, 3 May 2026 12:19:26 +0700 Subject: [PATCH] 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. --- themes/bonsai/i18n/en.toml | 14 ++++++++++++++ themes/bonsai/i18n/vi.toml | 13 +++++++++++++ themes/bonsai/layouts/partials/footer.html | 3 ++- .../layouts/partials/theme-toggle-button.html | 4 ++-- 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 themes/bonsai/i18n/en.toml create mode 100644 themes/bonsai/i18n/vi.toml diff --git a/themes/bonsai/i18n/en.toml b/themes/bonsai/i18n/en.toml new file mode 100644 index 0000000..95f7fb2 --- /dev/null +++ b/themes/bonsai/i18n/en.toml @@ -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 }}" diff --git a/themes/bonsai/i18n/vi.toml b/themes/bonsai/i18n/vi.toml new file mode 100644 index 0000000..a0f854b --- /dev/null +++ b/themes/bonsai/i18n/vi.toml @@ -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 }}" diff --git a/themes/bonsai/layouts/partials/footer.html b/themes/bonsai/layouts/partials/footer.html index 010630b..d46f292 100644 --- a/themes/bonsai/layouts/partials/footer.html +++ b/themes/bonsai/layouts/partials/footer.html @@ -3,7 +3,8 @@ {{- with site.Params.footerText -}}

{{ . | safeHTML }}

{{- else -}} -

© {{ now.Year }} {{ site.Params.name | default site.Title }}

+ {{- $ctx := dict "year" now.Year "name" (site.Params.name | default site.Title) -}} +

{{ i18n "footer_default" $ctx | default (printf "© %d %s" now.Year (site.Params.name | default site.Title)) | safeHTML }}

{{- end -}} {{- if site.Params.themeToggle -}} {{ partial "theme-toggle-button.html" . }} diff --git a/themes/bonsai/layouts/partials/theme-toggle-button.html b/themes/bonsai/layouts/partials/theme-toggle-button.html index 02041c2..8b81d65 100644 --- a/themes/bonsai/layouts/partials/theme-toggle-button.html +++ b/themes/bonsai/layouts/partials/theme-toggle-button.html @@ -2,9 +2,9 @@ Sun shown in dark mode (target = light). Moon shown in light mode (target = dark). */ -}}