Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,22 @@
be »
</a>
<script>
window.addEventListener('DOMContentLoaded', (event) => {
window.addEventListener('DOMContentLoaded', () => {
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;
}
Comment on lines +47 to +55

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.


const links = document.getElementsByClassName('intl');
const locale = window.navigator.language;
if (locale.startsWith('ja')) {
for(let i = 0; i < links.length; i++) {
links[i].setAttribute('href', links[i].getAttribute('href').replace('/en/', '/ja/'));
for (const link of links) {
const href = link.getAttribute('href');
if (href && href.includes('/en/')) {
link.setAttribute('href', href.replace('/en/', '/ja/'));
}
}
});
Expand Down
Loading