fix(seo): normalize locale codes to BCP 47 for lang and hreflang attributes#18246
Merged
Conversation
…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.
✅ Deploy Preview for ethereumorg ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
Author
|
@wackerow AI found this, not sure it's valid, not a rush, but whenever can you check? |
wackerow
approved these changes
May 28, 2026
Member
wackerow
left a comment
There was a problem hiding this comment.
Looks good! Checks/test look clean. Thanks!
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.

Summary
toLanguageTag()utility insrc/lib/utils/url.tsthat converts internal locale codes to valid BCP 47 language tags (pt-br→pt-BR,zh-tw→zh-TW)<html lang>attribute inapp/[locale]/layout.tsxsrc/lib/utils/metadata.tsandapp/sitemap.tsContext
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 HTMLlangattributes and hreflang language keys, which require BCP 47 format with uppercase region subtags (pt-BR,zh-TW). All other locales (single-segment likeen,fr,ar) are unaffected.Test plan
<html lang="pt-BR">and<html lang="zh-TW">are rendered on those locale pages<head>usept-BR/zh-TWas language keys/pt-br/,/zh-tw/) are unchanged