Skip to content

Commit b233a60

Browse files
committed
update i18n
1 parent 59ec746 commit b233a60

2 files changed

Lines changed: 4 additions & 26 deletions

File tree

static/js/main.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,4 @@ document.addEventListener('DOMContentLoaded', function() {
1919
localStorage.setItem('darkMode', 'disabled');
2020
}
2121
});
22-
23-
// --- 语言切换器逻辑 ---
24-
const langSwitcher = document.getElementById('lang-switcher');
25-
if (langSwitcher) {
26-
const currentPath = window.location.pathname;
27-
const currentLang = document.documentElement.lang.startsWith('zh') ? 'zh' : 'en';
28-
const otherLang = currentLang === 'en' ? 'zh' : 'en';
29-
30-
// 构造目标语言的对应页面路径
31-
let targetPath;
32-
if (currentPath.startsWith(`/${currentLang}/`)) {
33-
targetPath = currentPath.replace(`/${currentLang}/`, `/${otherLang}/`);
34-
} else {
35-
// 处理根目录跳转后的情况
36-
targetPath = `/${otherLang}/${currentPath.substring(1)}`;
37-
}
38-
39-
// 如果在根目录(比如跳转前的 index.html),则直接指向目标语言首页
40-
if (currentPath === '/' || currentPath === '/index.html') {
41-
targetPath = `/${otherLang}/`;
42-
}
43-
44-
langSwitcher.href = targetPath;
45-
}
46-
4722
});

templates/base.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@
3636
<li><a href="{{ base_url }}/{{ lang }}/about.html" class="{{ 'active' if nav_active == 'about' }}">{{ T('nav_about') }}</a></li>
3737
</ul>
3838
<div class="controls">
39-
<a href="#" id="lang-switcher" class="lang-switcher">{{ T('lang_switcher_text') }}</a>
39+
<!-- 找到另一个语言的代码 -->
40+
{% set other_lang = 'zh' if lang == 'en' else 'en' %}
41+
<!-- 直接生成包含 base_url 的完整链接 -->
42+
<a href="{{ base_url }}{{ alternate_paths[other_lang] }}" id="lang-switcher" class="lang-switcher">{{ T('lang_switcher_text') }}</a>
4043
<button id="dark-mode-toggle" class="dark-mode-toggle" aria-label="{{ T('dark_mode_label') }}">🌓</button>
4144
</div>
4245
</nav>

0 commit comments

Comments
 (0)