Skip to content
Open
Show file tree
Hide file tree
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
17 changes: 15 additions & 2 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const config = {
botId: process.env.BOT_ID,
patToken: process.env.TOKEN
},
// Add client module for language detection
clientModules: [require.resolve('./src/clientModules/lang-redirect.js')],
markdown: {
hooks: {
onBrokenMarkdownLinks: 'warn',
Expand Down Expand Up @@ -76,7 +78,18 @@ const config = {
],
i18n: {
defaultLocale: 'en',
locales: ['en', 'zh-CN'],
locales: ['en', 'zh-cn'],
localeConfigs: {
en: {
label: 'English',
htmlLang: 'en',
},
'zh-cn': {
label: '中文',
htmlLang: 'zh-CN',
path: 'zh-CN',
},
},
},
themeConfig:
({
Expand Down Expand Up @@ -136,7 +149,7 @@ const config = {
},
{
label: 'News',
to: 'news',
to: '/news',
},
{
label: 'Customer Stories',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ import useBaseUrl from '@docusaurus/useBaseUrl';
<div className="detail-wrapper">
<div className="detail-main">
<div className="breadcrumb">
<a href="/news">新闻动态</a> <span>&gt;</span> <span>社区动态</span>
<a href="/zh-cn/news">新闻动态</a> <span>&gt;</span> <span>社区动态</span>
</div>

<div className="post-header">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import useBaseUrl from '@docusaurus/useBaseUrl';
<div className="detail-wrapper">
<div className="detail-main">
<div className="breadcrumb">
<a href="/news">新闻动态</a> <span>&gt;</span> <span>正文内容</span>
<a href="/zh-cn/news">新闻动态</a> <span>&gt;</span> <span>正文内容</span>
</div>

<div className="post-header">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ import useBaseUrl from '@docusaurus/useBaseUrl';
<div className="detail-wrapper">
<div className="detail-main">
<div className="breadcrumb">
<a href="/news">新闻动态</a> <span>&gt;</span> <span>正文内容</span>
<a href="/zh-cn/news">新闻动态</a> <span>&gt;</span> <span>正文内容</span>
</div>

<div className="post-header">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ import useBaseUrl from '@docusaurus/useBaseUrl';
<div className="detail-wrapper">
<div className="detail-main">
<div className="breadcrumb">
<a href="/news">新闻动态</a> <span>&gt;</span> <span>正文内容</span>
<a href="/zh-cn/news">新闻动态</a> <span>&gt;</span> <span>正文内容</span>
</div>

<div className="post-header">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ import useBaseUrl from '@docusaurus/useBaseUrl';
<div className="detail-wrapper">
<div className="detail-main">
<div className="breadcrumb">
<a href="/news">新闻动态</a> <span>&gt;</span> <span>正文内容</span>
<a href="/zh-cn/news">新闻动态</a> <span>&gt;</span> <span>正文内容</span>
</div>

<div className="post-header">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ import useBaseUrl from '@docusaurus/useBaseUrl';
<div className="detail-wrapper">
<div className="detail-main">
<div className="breadcrumb">
<a href="/news">新闻动态</a> <span>&gt;</span> <span>正文内容</span>
<a href="/zh-cn/news">新闻动态</a> <span>&gt;</span> <span>正文内容</span>
</div>

<div className="post-header">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ import useBaseUrl from '@docusaurus/useBaseUrl';
<div className="detail-wrapper">
<div className="detail-main">
<div className="breadcrumb">
<a href="/news">新闻动态</a> <span>&gt;</span> <span>正文内容</span>
<a href="/zh-cn/news">新闻动态</a> <span>&gt;</span> <span>正文内容</span>
</div>

<div className="post-header">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ import useBaseUrl from '@docusaurus/useBaseUrl';
<div className="detail-wrapper">
<div className="detail-main">
<div className="breadcrumb">
<a href="/news">新闻动态</a> <span>&gt;</span> <span>开源之夏 2025 结项</span>
<a href="/zh-cn/news">新闻动态</a> <span>&gt;</span> <span>开源之夏 2025 结项</span>
</div>

<div className="post-header">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ import useBaseUrl from '@docusaurus/useBaseUrl';
<div className="detail-wrapper">
<div className="detail-main">
<div className="breadcrumb">
<a href="/news">新闻动态</a> <span>&gt;</span> <span>正文内容</span>
<a href="/zh-cn/news">新闻动态</a> <span>&gt;</span> <span>正文内容</span>
</div>

<div className="post-header">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ import useBaseUrl from '@docusaurus/useBaseUrl';
<div className="detail-wrapper">
<div className="detail-main">
<div className="breadcrumb">
<a href="/news">新闻动态</a> <span>&gt;</span> <span>正文内容</span>
<a href="/zh-cn/news">新闻动态</a> <span>&gt;</span> <span>正文内容</span>
</div>

<div className="post-header">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ import useBaseUrl from '@docusaurus/useBaseUrl';
<div className="detail-wrapper">
<div className="detail-main">
<div className="breadcrumb">
<a href="/news">新闻动态</a> <span>&gt;</span> <span>正文内容</span>
<a href="/zh-cn/news">新闻动态</a> <span>&gt;</span> <span>正文内容</span>
</div>

<div className="post-header">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ import useBaseUrl from '@docusaurus/useBaseUrl';
<div className="detail-wrapper">
<div className="detail-main">
<div className="breadcrumb">
<a href="/news">新闻动态</a> <span>&gt;</span> <span>正文内容</span>
<a href="/zh-cn/news">新闻动态</a> <span>&gt;</span> <span>正文内容</span>
</div>

<div className="post-header">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ import useBaseUrl from '@docusaurus/useBaseUrl';
<div className="detail-wrapper">
<div className="detail-main">
<div className="breadcrumb">
<a href="/news">新闻动态</a> <span>&gt;</span> <span>正文内容</span>
<a href="/zh-cn/news">新闻动态</a> <span>&gt;</span> <span>正文内容</span>
</div>

<div className="post-header">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ import useBaseUrl from '@docusaurus/useBaseUrl';
<div className="detail-wrapper">
<div className="detail-main">
<div className="breadcrumb">
<a href="/news">新闻动态</a> <span>&gt;</span> <span>IvorySQL 4.6 发布</span>
<a href="/zh-cn/news">新闻动态</a> <span>&gt;</span> <span>IvorySQL 4.6 发布</span>
</div>

<div className="post-header">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ import useBaseUrl from '@docusaurus/useBaseUrl';
<div className="detail-wrapper">
<div className="detail-main">
<div className="breadcrumb">
<a href="/news">新闻动态</a> <span>&gt;</span> <span>IvorySQL 5.0 发布</span>
<a href="/zh-cn/news">新闻动态</a> <span>&gt;</span> <span>IvorySQL 5.0 发布</span>
</div>

<div className="post-header">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ import useBaseUrl from '@docusaurus/useBaseUrl';
<div className="detail-wrapper">
<div className="detail-main">
<div className="breadcrumb">
<a href="/news">新闻动态</a> <span>&gt;</span> <span>IvorySQL 5.1 发布</span>
<a href="/zh-cn/news">新闻动态</a> <span>&gt;</span> <span>IvorySQL 5.1 发布</span>
</div>

<div className="post-header">
Expand Down
41 changes: 41 additions & 0 deletions src/clientModules/lang-redirect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Docusaurus Client Module for Language Detection
* This module runs on the client side and handles browser language detection
*/
export function onRouteDidUpdate({ location, previousLocation }) {
// Only run on root path
if (location.pathname !== '/' && location.pathname !== '/index.html') {
return;
}

// Check if user has an existing locale preference (manual language selection)
const savedLocale = localStorage.getItem('docusaurus.locale');
if (savedLocale === 'en') {
// User explicitly chose English, respect it and don't redirect
return;
}

if (savedLocale === 'zh-CN') {
// User chose Chinese, no need to redirect
return;
}

// Check if this is the first visit to the root path in this session
if (sessionStorage.getItem('clientLangDetectionDone')) {
return;
}

// Detect browser language
const browserLang = navigator.language || navigator.userLanguage || '';

// Redirect Chinese users to Chinese version
if (browserLang.toLowerCase().startsWith('zh')) {
// Mark as done before redirecting to prevent loops
sessionStorage.setItem('clientLangDetectionDone', '1');
// Redirect Chinese users to Chinese version
window.location.replace('/zh-CN/');
} else {
// Mark as done for non-Chinese users too
sessionStorage.setItem('clientLangDetectionDone', '1');
}
}
8 changes: 5 additions & 3 deletions static/_redirects
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Redirect users from China to chinese version at /zh-CN.
/ /zh-cn 302! Country=cn
# Also users with Chinese language should be redirected to /zh-cn
# / /zh-cn 302! Language=zh
# Disabled - relying on client-side browser language detection instead
# The ! flag causes forced redirects that prevent manual language switching
# / /zh-CN 302 Country=cn
# Also users with Chinese language should be redirected to /zh-CN
# / /zh-CN 302 Language=zh