Skip to content

Commit 11b655e

Browse files
committed
Change View page source to change language
1 parent fba1a1c commit 11b655e

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

pyarmor/ask/en/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ <h5 class="card-title">Ask Pyarmor</h5>
7777

7878
<script src="/pyarmor/assets/bootstrap-5.3.3/bootstrap.bundle.min.js"></script>
7979
<script>
80-
window.addEventListener('DOMContentLoaded', () => {
81-
document.querySelector('button.zh').addEventListener("click", (e) => {
82-
window.location.replace(window.location.href.replace('/en/', `/zh/`))
80+
window.addEventListener("DOMContentLoaded", () => {
81+
document.querySelector("button.zh").addEventListener("click", (e) => {
82+
window.location.replace(window.location.href.replace("/en/", "/zh/"))
8383
})
8484
})
8585
</script>

pyarmor/ask/zh/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ <h5 class="card-title">Pyarmor 解惑</h5>
7676

7777
<script src="/pyarmor/assets/bootstrap-5.3.3/bootstrap.bundle.min.js"></script>
7878
<script>
79-
window.addEventListener('DOMContentLoaded', () => {
80-
document.querySelector('button.en').addEventListener("click", (e) => {
81-
window.location.replace(window.location.href.replace('/zh/', `/en/`))
79+
window.addEventListener("DOMContentLoaded", () => {
80+
document.querySelector("button.en").addEventListener("click", (e) => {
81+
window.location.replace(window.location.href.replace("/zh/", "/en/"))
8282
})
8383
})
8484
</script>

pyarmor/docs/en/conf.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,19 @@
7070
# order to make the URL links work properly, an appropriate target
7171
# attribute must be set, such as "_top" and "_blank".
7272
graphviz_output_format = 'svg'
73+
74+
# Change language by modify `view page source`
75+
js_switch_lang = '''
76+
window.addEventListener("DOMContentLoaded", () => {
77+
// View page source
78+
const elment = document.querySelector("ul.wy-breadcrumbs > li.wy-breadcrumbs-aside > a")
79+
element.innerHTML = "中文"
80+
element.addEventListener("click", (e) => {
81+
e.preventDefault()
82+
window.location.replace(window.location.href.replace("/en/", "/zh/"))
83+
})
84+
'''
85+
86+
html_js_files = [
87+
(None, {'body': js_switch_lang}),
88+
]

pyarmor/docs/zh/conf.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,19 @@
7070
# order to make the URL links work properly, an appropriate target
7171
# attribute must be set, such as "_top" and "_blank".
7272
graphviz_output_format = 'svg'
73+
74+
# Change language by modify `view page source`
75+
js_switch_lang = '''
76+
window.addEventListener("DOMContentLoaded", () => {
77+
// View page source
78+
const elment = document.querySelector("ul.wy-breadcrumbs > li.wy-breadcrumbs-aside > a")
79+
element.innerHTML = "English"
80+
element.addEventListener("click", (e) => {
81+
e.preventDefault()
82+
window.location.replace(window.location.href.replace("/zh/", "/en/"))
83+
})
84+
'''
85+
86+
html_js_files = [
87+
(None, {'body': js_switch_lang}),
88+
]

0 commit comments

Comments
 (0)