Fix language selector to preserve anchor links
What does this MR do and why?
The language selector now retains anchor links when switching between languages, ensuring users stay at the same section of the page after language changes.
Changes:
- Modified onLanguageSelect method to append current page hash to target URL
- Maintains existing behavior when no anchor links are present
Before: Switching languages would navigate to the top of the page
After: Users remain at the same section (e.g., #installation → /ja-jp/docs/page#installation)
Works with pages fully translated with english anchor links, such as /ja-jp/ci/yaml/#global-keywords
For pages that don't have the english anchor link, that page just loads at the top.
Closes gitlab-com/localization/docs-site-localization#295 (closed)
Screenshots, screen recordings, or links to review app
These are strongly recommended to assist reviewers and reduce the time to merge your change.
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
- Enable Japanese in config/_default/hugo.yml
- Run site locally with
make view - Navigate to sub page and use the sidenav to append an anchor link to the URL, for example
/ci/yaml/#artifactspaths - Switch language, see the anchor link preserved
Merge request acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this merge request.