Fix Language API for Hugo multi-language support - #1
Merged
Conversation
There was a problem hiding this comment.
🟡 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.yamllanguage configuration to uselanguageNameinstead oflabel. - Updated the header language switcher to use
.Language.LanguageNameand to resolve a target-language page viaGetPage, 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
languageNamefor compatibility with Hugo version 0.146.0..Language.Labelwith.Language.LanguageNameto ensure proper language switching functionality.GetPageto find the corresponding page in the target language.Validation:
hugo --minify, confirming that the changes resolved the previous build errors.Environment:
v0.165.0 extended0.146.0This update ensures that the site can successfully build and switch between English and Chinese without errors.