Skip to content

✨ Add opt-in client-side language redirect#2935

Open
aplgr wants to merge 3 commits into
nunocoracao:mainfrom
aplgr:feature/client-language-redirect
Open

✨ Add opt-in client-side language redirect#2935
aplgr wants to merge 3 commits into
nunocoracao:mainfrom
aplgr:feature/client-language-redirect

Conversation

@aplgr
Copy link
Copy Markdown
Contributor

@aplgr aplgr commented May 10, 2026

Summary

This PR adds an optional client-side language redirect feature for multilingual Blowfish sites.

Related discussion: #2934

The feature is fully opt-in and disabled by default. Existing sites keep their current behavior unless they explicitly enable the new languageRedirect configuration.

Problem

Blowfish already provides a language dropdown for multilingual sites, but visitors still land on the configured default content language first.

For static multilingual sites without server-side language negotiation, this means that a visitor whose browser prefers another supported language has to switch manually, even when a translated version already exists.

Solution

This PR introduces a small client-side redirect helper that:

  • detects the browser language on first visit
  • redirects only when a matching translation exists
  • stores explicit language selections from the existing language dropdown in localStorage
  • respects the stored language preference on later visits
  • avoids redirect loops
  • does not require cookies or any server-side component

The browser-language redirect is limited to home pages by default to avoid surprising users who open deep links. Stored language preferences can still be respected on translated pages when a matching translation exists.

The matching logic preserves locale subtags where available, so sites using variants such as pt-BR / pt-PT or zh-Hans / zh-Hant can still honor the visitor’s exact browser preference before falling back to a base language match.

Configuration

The feature can be enabled with:

[languageRedirect]
  enabled = true
  storageKey = "blowfish_preferred_language"
  fallbackLanguage = "en"
  browserRedirectHomeOnly = true
  storedLanguageRedirect = true

Backward compatibility

This is disabled by default.

No existing multilingual behavior changes unless the site owner explicitly enables:

[languageRedirect]
  enabled = true

Notes

The implementation is intentionally client-side only and uses the existing Hugo/Blowfish multilingual data, especially .AllTranslations, instead of introducing any server-side requirements or external dependencies.

@aplgr aplgr requested a review from nunocoracao as a code owner May 10, 2026 13:52
@netlify
Copy link
Copy Markdown

netlify Bot commented May 10, 2026

Deploy Preview for snazzy-dango-efb2ec ready!

Name Link
🔨 Latest commit 6b11b81
🔍 Latest deploy log https://app.netlify.com/projects/snazzy-dango-efb2ec/deploys/6a05cce98fe2c70008110421
😎 Deploy Preview https://deploy-preview-2935--snazzy-dango-efb2ec.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3a86a7656e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread assets/js/language-redirect.js Outdated
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