Skip to content

fix(seo): normalize locale codes to BCP 47 for lang and hreflang attributes#18246

Merged
wackerow merged 1 commit into
devfrom
fix/qa-weekly-issues-may-2026
May 28, 2026
Merged

fix(seo): normalize locale codes to BCP 47 for lang and hreflang attributes#18246
wackerow merged 1 commit into
devfrom
fix/qa-weekly-issues-may-2026

Conversation

@nloureiro
Copy link
Copy Markdown
Contributor

@nloureiro nloureiro commented May 21, 2026

Summary

  • Adds toLanguageTag() utility in src/lib/utils/url.ts that converts internal locale codes to valid BCP 47 language tags (pt-brpt-BR, zh-twzh-TW)
  • Applies it to the HTML <html lang> attribute in app/[locale]/layout.tsx
  • Applies it to hreflang language keys in src/lib/utils/metadata.ts and app/sitemap.ts

Context

Identified via ahrefs weekly crawl (20 May 2026): 142 "HTML lang attribute invalid" errors.

Internal locale codes use lowercase region subtags (e.g. pt-br, zh-tw) as URL path segments — that is intentional and unchanged. But the same raw codes were being used as HTML lang attributes and hreflang language keys, which require BCP 47 format with uppercase region subtags (pt-BR, zh-TW). All other locales (single-segment like en, fr, ar) are unaffected.

Test plan

  • Verify <html lang="pt-BR"> and <html lang="zh-TW"> are rendered on those locale pages
  • Verify hreflang tags in page <head> use pt-BR / zh-TW as language keys
  • Verify sitemap hreflang alternates use BCP 47 casing
  • Verify URL paths (/pt-br/, /zh-tw/) are unchanged

…ibutes

Locale codes pt-br and zh-tw are used as URL path segments (intentional)
but were also used directly as HTML lang attributes and hreflang language
keys, which require uppercase region subtags per BCP 47 (pt-BR, zh-TW).

Adds toLanguageTag() utility and applies it in:
- app/[locale]/layout.tsx: <html lang>
- src/lib/utils/metadata.ts: hreflang language keys
- app/sitemap.ts: sitemap hreflang alternates

Fixes ~142 "HTML lang attribute invalid" ahrefs errors.
@netlify
Copy link
Copy Markdown

netlify Bot commented May 21, 2026

Deploy Preview for ethereumorg ready!

Name Link
🔨 Latest commit 7ce492c
🔍 Latest deploy log https://app.netlify.com/projects/ethereumorg/deploys/6a0ebcca96dd4f00089d7985
😎 Deploy Preview https://deploy-preview-18246.ethereum.it
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
7 paths audited
Performance: 71 (🟢 up 7 from production)
Accessibility: 96 (no change from production)
Best Practices: 100 (🟢 up 1 from production)
SEO: 98 (🔴 down 1 from production)
PWA: 59 (no change from production)
View the detailed breakdown and full score reports

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

@github-actions github-actions Bot added the tooling 🔧 Changes related to tooling of the project label May 21, 2026
@nloureiro
Copy link
Copy Markdown
Contributor Author

@wackerow AI found this, not sure it's valid, not a rush, but whenever can you check?

Copy link
Copy Markdown
Member

@wackerow wackerow left a comment

Choose a reason for hiding this comment

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

Looks good! Checks/test look clean. Thanks!

@wackerow wackerow merged commit bfe5cb9 into dev May 28, 2026
16 checks passed
@wackerow wackerow deleted the fix/qa-weekly-issues-may-2026 branch May 28, 2026 13:46
@pettinarip pettinarip mentioned this pull request May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tooling 🔧 Changes related to tooling of the project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants