Redirect unsupported locale prefixes to English - #5588
Open
zandonella wants to merge 1 commit into
Open
Conversation
Redirects paths with an unsupported locale-shaped prefix (e.g. `/cn`) to the English equivalent and shows a one-time banner noting the missing translation.
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.
Fixes
Fixes #575 by @sarayourfriend
Description
Currently, visiting a path with an unsupported, locale-shaped prefix (e.g.
openverse.org/cn) matches no route and renders a 404 page.This PR adds a global route middleware that detects these paths, strips the locale-shaped prefix, and redirects to the English equivalent. On the page the visitor lands on, a one-time banner explains that Openverse isn't translated into the requested language yet and links to the project page where they can contribute a translation.
Details:
getUnsupportedLocaleRedirectutil detects a locale-shaped first path segment (two letters, optional hyphenated region — e.g.cn,es-ar) that isn't in the configured locale set, and returns the prefix-stripped (English) path.unsupported-locale.globalmiddleware performs the redirect for unmatched routes and controls banner visibility.uistore persists anunsupportedLocaleRedirectflag so it survives the server-side redirect, then consumes it on the landing page to show the transient banner once. The banner is hidden on any subsequent navigation.VUnsupportedLocaleBannercomponent, wired intoVBanners, with newnotification.unsupportedLocale.*strings.Testing Instructions
http://localhost:8443/cn(or/cn/search?q=cat)./or/search?q=cat) rather than seeing a 404, and that the "language not supported" banner appears once./es) and a genuinely unknown path (e.g./foobar) are unaffected.ov just frontend/run test:unit unsupported-locale.Checklist
Update index.md).main) or a parent feature branch.ov just catalog/generate-docsfor catalogPRs) or the media properties generator (
ov just catalog/generate-docs media-propsfor the catalog or
ov just api/generate-docsfor the API) where applicable.Developer Certificate of Origin
Developer Certificate of Origin