Skip to content

Fix Language API for Hugo multi-language support - #1

Merged
IndexFlowing merged 1 commit into
mainfrom
agents/rename-to-sanfeng-zhangsanfeng
Sep 8, 2026
Merged

Fix Language API for Hugo multi-language support#1
IndexFlowing merged 1 commit into
mainfrom
agents/rename-to-sanfeng-zhangsanfeng

Conversation

@IndexFlowing

Copy link
Copy Markdown
Owner

This pull request addresses the build error related to the Hugo multi-language feature by updating the language API usage in the project.

Changes Made:

  • hugo.yaml: Updated the language display names to use languageName for compatibility with Hugo version 0.146.0.
  • header.html: Replaced .Language.Label with .Language.LanguageName to ensure proper language switching functionality.
    • Improved the logic for determining the target language page by checking the configured languages and using GetPage to find the corresponding page in the target language.
    • Ensured that the language switcher remains consistent with the existing design.

Validation:

  • The project was built successfully using the command hugo --minify, confirming that the changes resolved the previous build errors.
  • Language switching functionality was tested across various page types, ensuring that it works correctly without altering the existing URL structure or design.

Environment:

  • Local Hugo version: v0.165.0 extended
  • CI Hugo version: 0.146.0

This update ensures that the site can successfully build and switch between English and Chinese without errors.

Copilot AI lite review requested due to automatic review settings September 8, 2026 02:56
@IndexFlowing
IndexFlowing merged commit 6f62f97 into main Sep 8, 2026
1 check passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The updated language switcher can call GetPage with a non-supported home kind and also ignores the disableLangToggle site setting, which can lead to build/runtime issues and config regression.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Updates the site’s Hugo multi-language configuration and header language switcher to align with Hugo’s current language API, resolving build failures related to deprecated language label fields.

Changes:

  • Updated hugo.yaml language configuration to use languageName instead of label.
  • Updated the header language switcher to use .Language.LanguageName and to resolve a target-language page via GetPage, falling back to the target language’s home page.
File summaries
File Description
layouts/_partials/header.html Reworked language switcher to use Hugo’s newer language name API and attempt cross-language page resolution.
hugo.yaml Migrated language display name config keys to Hugo’s supported languageName.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

{{- $translations := .Translations }}
{{- if not $translations }}{{ $translations = site.Home.Translations }}{{ end }}
{{- with $translations }}
{{- if hugo.IsMultilingual }}
{{- if hugo.IsMultilingual }}
<span class="nav-sep">|</span>
<ul class="lang-menu">{{ range . }}<li><a href="{{ .RelPermalink }}" data-language-preference="{{ .Lang }}" title="{{ .Language.Params.languageAltTitle | default .Language.Label }}">{{ .Language.Label | default (.Lang | title) }}</a></li>{{ end }}</ul>
<ul class="lang-menu">{{ range hugo.Sites }}{{ if ne .Language.Lang $.Language.Lang }}{{ $fallbackURL := .Home.RelPermalink }}{{ $targetPage := .GetPage $.Kind $.Path }}<li><a href="{{ with $targetPage }}{{ .RelPermalink }}{{ else }}{{ $fallbackURL }}{{ end }}" data-language-preference="{{ .Language.Lang }}" title="{{ .Language.Params.languageAltTitle | default .Language.LanguageName }}">{{ .Language.LanguageName | default (.Language.Lang | title) }}</a></li>{{ end }}{{ end }}</ul>
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.

3 participants