Detect default homepage language from browser locale#20
Merged
Conversation
Copilot created this pull request from a session on behalf of
afc163
July 2, 2026 05:54
View session
✅ Preview is ready!
↩️ Previous: ⚡️ 🤖 Powered by surge-preview |
|||||||||||||||
Deploying afx-team with
|
| Latest commit: |
0b4eefa
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://28fe3acf.afx-team.pages.dev |
| Branch Preview URL: | https://copilot-add-default-language.afx-team.pages.dev |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the site’s i18n initialization so the homepage default language is derived from the browser locale (when ?lang= is not explicitly provided), and adds automated coverage for the new language-resolution behavior.
Changes:
- Add language normalization (
en-*/zh-*→en/zh) plus browser-locale detection injs/i18n.js. - Change
I18nManagerstartup to usegetInitialLanguage()instead of defaulting to Chinese unconditionally. - Extend
tests/aria-label-i18n.test.mjsto executejs/i18n.jsin a VM and assert default/override behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
js/i18n.js |
Introduces initial-language resolution (URL override → browser locale fallback) and normalization. |
tests/aria-label-i18n.test.mjs |
Adds VM-based tests covering language defaults and URL ?lang= precedence. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+81
to
+86
| getInitialLanguage() { | ||
| const urlLanguage = this.getLanguageFromURL(); | ||
|
|
||
| if (urlLanguage !== null) { | ||
| return this.normalizeLanguage(urlLanguage) || 'en'; | ||
| } |
Comment on lines
+128
to
+135
| test('invalid lang query ignores browser locale and falls back to English', () => { | ||
| const manager = createI18nManager({ | ||
| search: '?lang=fr', | ||
| language: 'zh-CN', | ||
| }); | ||
|
|
||
| assert.equal(manager.currentLang, 'en'); | ||
| }); |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.

Direct visits to
https://afx-team.github.io/always started in Chinese unless?lang=enwas present. This change makes the homepage choose English or Chinese from the browser locale by default, while preserving explicit?lang=overrides.Language selection
js/i18n.js?lang=as the highest-priority sourcenavigator.languages/navigator.languageen-US,en-GB,zh-CN,zh-TWtoen/zhFallback behavior
?lang=is explicitly providedCoverage
?lang=taking precedence?lang=falling back to Chinese