Skip to content

Commit c1b4dbb

Browse files
committed
fix issue with language switching
1 parent 9b7e931 commit c1b4dbb

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/components/MobileSideBarMenu/MobileLanguagePicker.jsx

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -127,25 +127,24 @@ const MobileLanguagePicker = () => {
127127
let currentPath = location.pathname;
128128

129129
// Handle docs paths
130-
if (currentPath.startsWith('/docs/')) {
131-
// Remove existing locale from docs path
132-
let cleanPath = currentPath.replace(/^\/docs\/(jp|ja|ru|zh|zh-CN)(?=\/|$)/, '/docs');
133-
134-
// If no locale was removed, we're already on a clean path
135-
if (cleanPath === currentPath) {
136-
cleanPath = currentPath;
137-
}
138-
139-
// Build new URL with target locale
140-
if (locale === i18n.defaultLocale || locale === 'en') {
141-
// English: keep clean path as-is
142-
href = cleanPath;
143-
} else {
144-
// Other languages: inject locale after /docs
145-
if (cleanPath === '/docs' || cleanPath === '/docs/') {
130+
if (currentPath.startsWith('/docs')) {
131+
// Handle docs root paths specifically
132+
if (currentPath === '/docs' || currentPath === '/docs/') {
133+
if (locale === i18n.defaultLocale || locale === 'en') {
134+
href = '/docs/';
135+
} else {
146136
href = `/docs/${locale}/`;
137+
}
138+
} else {
139+
// Remove existing locale from docs path if present
140+
let cleanPath = currentPath.replace(/^\/docs\/(jp|ja|ru|zh|zh-CN)(?=\/|$)/, '/docs');
141+
142+
// Build new URL with target locale
143+
if (locale === i18n.defaultLocale || locale === 'en') {
144+
href = cleanPath;
147145
} else {
148-
href = cleanPath.replace('/docs/', `/docs/${locale}/`);
146+
// For non-English locales, inject locale after /docs
147+
href = cleanPath.replace('/docs', `/docs/${locale}`);
149148
}
150149
}
151150
} else {

0 commit comments

Comments
 (0)