Skip to content

Improve locale-aware manual links - #27

Merged
koriym merged 1 commit into
masterfrom
codex/locale-manual-links
Apr 30, 2026
Merged

koriym merged 1 commit into
masterfrom
codex/locale-manual-links

Conversation

@koriym

@koriym koriym commented Apr 23, 2026 •

Copy link
Copy Markdown
Contributor

What changed

  • updated the landing-page locale helper to use navigator.languages with navigator.language fallback
  • kept the manual entry link English by default and switched it to Japanese only for Japanese-preferring browsers

Why

  • this aligns the site with the newer locale handling used across the manual sites
  • it improves browser-language matching without changing the underlying URL structure

Notes

  • this PR contains only the locale-link commit and is based on master
  • git pull could not be completed from this environment because github.com DNS resolution failed at the time of execution

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced Japanese language detection to check the user's browser language preferences more comprehensively
    • Improved localization routing to accurately update navigation links for Japanese content when applicable

@coderabbitai

coderabbitai Bot commented Apr 23, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The DOMContentLoaded handler's language detection logic has been enhanced to scan the user's preferred language list (navigator.languages) for Japanese locales with a fallback mechanism, and validation has been added to ensure href attributes contain /en/ before replacement with /ja/.

Changes

Cohort / File(s) Summary
Language Detection Enhancement
index.html
Updated language preference detection to check navigator.languages array for Japanese locales before falling back to navigator.language. Added validation to only update .intl links with non-null href attributes that contain /en/ segment.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A rabbit hops through language paths,
Checking preferences with newfound care,
Japanese seeks through nav.languages' baths,
With validation that shows true flair,
No broken links shall hide anywhere!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Improve locale-aware manual links' directly summarizes the main change: enhancing the locale detection logic for manual links to use navigator.languages with fallback, improving browser-language matching.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/locale-manual-links

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@claude

claude Bot commented Apr 23, 2026

Copy link
Copy Markdown

Code Review: PR #27 — Improve locale-aware manual links

Overview

This PR improves the browser locale detection on the landing page by switching from the single navigator.language to the prioritized navigator.languages array, with a safe fallback. It also modernizes the loop and adds a null-guard on href.


Code Quality — Good

  • navigator.languages is the right API. It returns the user's full ordered preference list (e.g. ['ja-JP', 'ja', 'en-US']), which is far more reliable than the single navigator.language. This is a meaningful accuracy improvement.
  • Early return pattern (if (!prefersJapanese) return;) improves readability by eliminating the outer if nesting.
  • for...of loop is idiomatic modern JS and cleaner than the index-based loop.
  • Null-guard (if (href && href.includes('/en/'))) is good defensive coding; prevents null.replace() on links that somehow lack an href.
  • Removing the unused event parameter from the DOMContentLoaded callback is a minor but clean fix.

Potential Issues / Suggestions

  1. Fallback array shape when navigator.language is undefined:

    [window.navigator.language ?? '']

    If navigator.language is undefined (very old browsers), this produces ['']. ''.toLowerCase().startsWith('ja') correctly returns false, so the behavior is safe — no action needed.

  2. locale.toLowerCase() applied to the full BCP 47 tag (e.g. 'ja-JP'): startsWith('ja') still matches correctly since 'ja-jp'.startsWith('ja') is true. The toLowerCase() call is defensive rather than strictly necessary for this check, but it's harmless.

  3. No semicolons after the listener block — pre-existing style, consistent with the rest of the file.


Security

No concerns. The replacement is constrained to elements with class intl and only transforms /en/ → /ja/ in the existing href. No user-controlled content is injected into the DOM.


Verdict

Ready to merge. Clean, focused improvement with no regressions.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@index.html`:
- Around line 47-55: The current logic uses locales.some(...) which ignores the
browser's preferred-order; instead pick the first supported locale in priority
order and only switch when that primary locale is Japanese. Update the code
around navigatorLanguages/locales/prefersJapanese: define a supportedLocales set
(e.g. ['ja', 'en', ...] as appropriate), iterate locales in order to find
primaryLocale = locales.find(l =>
supportedLocales.has(l.slice(0,2).toLowerCase())) ?? locales[0], then set
prefersJapanese = primaryLocale.toLowerCase().startsWith('ja') and keep the
early return if false. This preserves navigator.languages priority and only
switches when the top-supported locale is Japanese.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 00a3f09b-93bd-4b72-9bec-c5985597b893

📥 Commits

Reviewing files that changed from the base of the PR and between 05d0930 and b4c7ff2.

📒 Files selected for processing (1)
  • index.html

Comment thread index.html
Comment on lines +47 to +55
const navigatorLanguages = window.navigator.languages;
const locales = (navigatorLanguages && navigatorLanguages.length)
? navigatorLanguages
: [window.navigator.language ?? ''];
const prefersJapanese = locales.some((locale) => locale.toLowerCase().startsWith('ja'));

if (!prefersJapanese) {
return;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Respect the browser’s locale priority order.

Using .some() switches to Japanese even for navigator.languages = ['en-US', 'ja-JP'], where English is the preferred supported locale. Consider choosing the first supported locale, then switching only when that locale is Japanese.

🌐 Proposed locale-priority fix
             const locales = (navigatorLanguages && navigatorLanguages.length)
                 ? navigatorLanguages
                 : [window.navigator.language ?? ''];
-            const prefersJapanese = locales.some((locale) => locale.toLowerCase().startsWith('ja'));
+            const preferredSupportedLocale = locales
+                .map((locale) => locale.toLowerCase())
+                .find((locale) => locale.startsWith('ja') || locale.startsWith('en'));
+            const prefersJapanese = preferredSupportedLocale?.startsWith('ja') ?? false;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const navigatorLanguages = window.navigator.languages;
const locales = (navigatorLanguages && navigatorLanguages.length)
? navigatorLanguages
: [window.navigator.language ?? ''];
const prefersJapanese = locales.some((locale) => locale.toLowerCase().startsWith('ja'));
if (!prefersJapanese) {
return;
}
const navigatorLanguages = window.navigator.languages;
const locales = (navigatorLanguages && navigatorLanguages.length)
? navigatorLanguages
: [window.navigator.language ?? ''];
const preferredSupportedLocale = locales
.map((locale) => locale.toLowerCase())
.find((locale) => locale.startsWith('ja') || locale.startsWith('en'));
const prefersJapanese = preferredSupportedLocale?.startsWith('ja') ?? false;
if (!prefersJapanese) {
return;
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@index.html` around lines 47 - 55, The current logic uses locales.some(...)
which ignores the browser's preferred-order; instead pick the first supported
locale in priority order and only switch when that primary locale is Japanese.
Update the code around navigatorLanguages/locales/prefersJapanese: define a
supportedLocales set (e.g. ['ja', 'en', ...] as appropriate), iterate locales in
order to find primaryLocale = locales.find(l =>
supportedLocales.has(l.slice(0,2).toLowerCase())) ?? locales[0], then set
prefersJapanese = primaryLocale.toLowerCase().startsWith('ja') and keep the
early return if false. This preserves navigator.languages priority and only
switches when the top-supported locale is Japanese.

@koriym
koriym merged commit 150db3d into master Apr 30, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant