Skip to content

fix(translations): fall back to base language tag for Accept-Language matching#15076

Merged
PatrikKozak merged 5 commits intopayloadcms:mainfrom
Robot-Inventor:fallback-to-base-lang
Apr 9, 2026
Merged

fix(translations): fall back to base language tag for Accept-Language matching#15076
PatrikKozak merged 5 commits intopayloadcms:mainfrom
Robot-Inventor:fallback-to-base-lang

Conversation

@Robot-Inventor
Copy link
Copy Markdown
Contributor

Why?

Some browsers send only regional tags like ja-JP in the Accept-Language header. When no exact match exists, the current behavior can fail to detect a supported base language, leading to missed localization.

What?

Allow language detection to fall back from a regional tag (e.g., ja-JP) to its base tag (ja) when the exact match is not supported.

How?

While parsing Accept-Language, check for an exact match in acceptedLanguages, and if none is found, split on - and try the base language tag before giving up.

matching

\### Why?

Some browsers send only regional tags like `ja-JP` in the
`Accept-Language` header. When no exact match exists, the current
behavior can fail to detect a supported base language, leading to missed
localization.

\### What?

Allow language detection to fall back from a regional tag (e.g.,
`ja-JP`) to its base tag (`ja`) when the exact match is not supported.

\### How?

While parsing `Accept-Language`, check for an exact match in
`acceptedLanguages`, and if none is found, split on `-` and try the base
language tag before giving up.
@PatrikKozak PatrikKozak self-requested a review April 9, 2026 17:29
@PatrikKozak PatrikKozak self-assigned this Apr 9, 2026
@PatrikKozak PatrikKozak enabled auto-merge (squash) April 9, 2026 17:55
@PatrikKozak PatrikKozak merged commit cf95cad into payloadcms:main Apr 9, 2026
323 of 326 checks passed
@Robot-Inventor Robot-Inventor deleted the fallback-to-base-lang branch April 9, 2026 19:19
@github-actions
Copy link
Copy Markdown
Contributor

🚀 This is included in version v3.83.0

milamer pushed a commit to milamer/payload that referenced this pull request Apr 20, 2026
… matching (payloadcms#15076)

### Why?

Some browsers send only regional tags like `ja-JP` in the
`Accept-Language` header. When no exact match exists, the current
behavior can fail to detect a supported base language, leading to missed
localization.

### What?

Allow language detection to fall back from a regional tag (e.g.,
`ja-JP`) to its base tag (`ja`) when the exact match is not supported.

### How?

While parsing `Accept-Language`, check for an exact match in
`acceptedLanguages`, and if none is found, split on `-` and try the base
language tag before giving up.

---------

Co-authored-by: Patrik Kozak <35232443+PatrikKozak@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants