Skip to content

Add i18n function support and centralized data access#95

Open
lenucksi wants to merge 1 commit intojhvanderschee:mainfrom
lenucksi:feature/i18n-function-support
Open

Add i18n function support and centralized data access#95
lenucksi wants to merge 1 commit intojhvanderschee:mainfrom
lenucksi:feature/i18n-function-support

Conversation

@lenucksi
Copy link
Copy Markdown
Contributor

@lenucksi lenucksi commented Sep 17, 2025

Summary

  • Enable Hugo's native i18n system alongside centralized data configuration for better translation management and data organization
  • Add support for {{ i18n "key" }} function calls in footerlogo partial for theme-independent translations
  • Enable centralized data access via Site.Data.settings for contact info and titles to reduce duplication
  • Maintain backward compatibility with language-specific data files
  • Add graceful fallbacks for missing translations or centralized data

Benefits

  • Hugo native i18n support with {{ i18n }} function calls enables theme-independent translations
  • Centralized data management reduces duplication across languages
  • Backward compatible - existing language-specific configurations continue working
  • Better separation of concerns between translatable and non-translatable content
  • Enables proper i18n workflows following Hugo best practices

Usage Examples

i18n translations:

# i18n/en.yaml
footer_text:
  other: "Copyright © 2024"
secure_contact:
  other: "Secure contact"

# i18n/de.yaml  
footer_text:
  other: "Copyright © 2024"
secure_contact:
  other: "Sicherer Kontakt"

Centralized data:

# data/settings.yaml
title: "My Site"
contact:
  phone: "+1234567890"
  email: "hello@example.com"

Template usage:

{{ i18n "footer_text" }}              // Uses i18n translations
{{ .Site.Data.settings.title }}       // Uses centralized data

Implementation

  • Templates check for i18n translations first, fall back to language-specific data
  • Centralized data access with graceful fallbacks
  • Maintains all existing CSS classes and structure
  • Updates footerlogo, logo, and contactbuttons partials

Notice:

  • I have changed these things in a website based on your template repo (thanks a lot for it!), it works properly there. Intent there was to centralize more common data into a single file and use more of the built-in i18n features where it might make sense.
  • I then asked Claude to extract my changes from the original I use to a more anonymized version that might be upstream worthy. Claude appears to have put in these "you may also use the old version" parts, I have entirely removed menu i18n based on the old system.
  • Maybe it's useful, maybe it isn't (it is at least for me) so feel free to just close it or tweak it (e.g. by also ripping out the old approach) such that it becomes merge-worthy.
    -> 🤖 Generated with Claude Code

Enable Hugo's native i18n system alongside centralized data configuration
for better translation management and data organization.

- Add support for {{ i18n "key" }} function calls in footerlogo partial
- Enable centralized data access via Site.Data.settings for contact info and titles
- Maintain backward compatibility with language-specific data files
- Add graceful fallbacks for missing translations or centralized data
- Support proper i18n workflows for theme-independent translations

Benefits:
- Hugo native i18n support with {{ i18n }} function calls
- Centralized data management reduces duplication across languages
- Backward compatible - existing language-specific configurations continue working
- Better separation of concerns between translatable and non-translatable content
- Enables proper theme-independent i18n workflows

Usage examples:

i18n/en.yaml:
footer_text:
  other: "Copyright © 2024"

data/settings.yaml:
title: "My Site"
contact:
  phone: "+1234567890"
  email: "hello@example.com"

Template usage:
{{ i18n "footer_text" }}          # Uses i18n translations
{{ .Site.Data.settings.title }}     # Uses centralized data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant