mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-26 07:04:12 +08:00
.
This commit is contained in:
parent
e01c35d370
commit
c9a67cc395
@ -44,9 +44,7 @@
|
|||||||
<span class="goodlinknormal">
|
<span class="goodlinknormal">
|
||||||
语言/Language
|
语言/Language
|
||||||
</span>
|
</span>
|
||||||
<div class="dropdown-content ">
|
<div class="dropdown-content " id="languageswitch">
|
||||||
<a class="goodlink buttonsize" onclick="switchlang(`zh`)">简体中文<br></a>
|
|
||||||
<a class="goodlink buttonsize" onclick="switchlang(`en`)">English<br></a>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
134
docs/main.js
134
docs/main.js
@ -1,4 +1,55 @@
|
|||||||
|
const supportlangs = { zh: '简体中文', en: 'English', ja: '日本語' }
|
||||||
|
const langs = {
|
||||||
|
clipboardok: {
|
||||||
|
zh: '已复制到剪贴板',
|
||||||
|
en: 'Copy to clipboard',
|
||||||
|
ja: 'クリップボードにコピーされました'
|
||||||
|
},
|
||||||
|
homepage: {
|
||||||
|
zh: '官方网站',
|
||||||
|
en: 'HomePage',
|
||||||
|
ja: '公式サイト'
|
||||||
|
|
||||||
|
},
|
||||||
|
downloadlink: {
|
||||||
|
zh: '软件下载',
|
||||||
|
en: 'Download',
|
||||||
|
ja: 'ダウンロード'
|
||||||
|
},
|
||||||
|
vediotutorial: {
|
||||||
|
zh: '视频教学',
|
||||||
|
en: 'Vedio Tutorial',
|
||||||
|
ja: 'ビデオチュー'
|
||||||
|
},
|
||||||
|
contactme: {
|
||||||
|
zh: 'QQ群963119821',
|
||||||
|
en: 'Discord',
|
||||||
|
ja: 'Discord'
|
||||||
|
},
|
||||||
|
bit64link: {
|
||||||
|
zh: '64位',
|
||||||
|
en: '64-bit',
|
||||||
|
ja: '64ビット'
|
||||||
|
},
|
||||||
|
bit32link: {
|
||||||
|
zh: '32位',
|
||||||
|
en: '32-bit',
|
||||||
|
ja: '32ビット'
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const languagelinks = {
|
||||||
|
contactme: {
|
||||||
|
zh: 'https://qm.qq.com/q/I5rr3uEpi2',
|
||||||
|
en: 'https://discord.com/invite/ErtDwVeAbB',
|
||||||
|
ja: 'https://discord.com/invite/ErtDwVeAbB',
|
||||||
|
},
|
||||||
|
vediotutorial: {
|
||||||
|
zh: 'https://space.bilibili.com/592120404/video',
|
||||||
|
en: 'https://www.youtube.com/results?search_query=LunaTranslator',
|
||||||
|
ja: 'https://www.youtube.com/results?search_query=LunaTranslator',
|
||||||
|
}
|
||||||
|
}
|
||||||
window.$docsify = {
|
window.$docsify = {
|
||||||
// homepage: '/redirect.html',
|
// homepage: '/redirect.html',
|
||||||
requestHeaders: {
|
requestHeaders: {
|
||||||
@ -16,6 +67,7 @@ window.$docsify = {
|
|||||||
alias: {
|
alias: {
|
||||||
'/zh/_sidebar.md': '/zh/sidebar.md',
|
'/zh/_sidebar.md': '/zh/sidebar.md',
|
||||||
'/en/_sidebar.md': '/en/sidebar.md',
|
'/en/_sidebar.md': '/en/sidebar.md',
|
||||||
|
'/ja/_sidebar.md': '/ja/sidebar.md',
|
||||||
'/_navbar.md': '/navbar.md',
|
'/_navbar.md': '/navbar.md',
|
||||||
'/_coverpage.md': '/coverpage.md',
|
'/_coverpage.md': '/coverpage.md',
|
||||||
},
|
},
|
||||||
@ -113,40 +165,20 @@ for (let i = 0; i < dropdowns.length; i++) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var currentlang = "";
|
var currentlang = "";
|
||||||
const navitexts = {
|
|
||||||
zh: {
|
|
||||||
homepage: '官方网站',
|
|
||||||
downloadlink: '软件下载',
|
|
||||||
vediotutorial: '视频教学',
|
|
||||||
contactme: 'QQ群963119821',
|
|
||||||
bit64link: '64位',
|
|
||||||
bit32link: '32位'
|
|
||||||
|
|
||||||
},
|
for (let lang in supportlangs) {
|
||||||
en: {
|
console.log(lang)
|
||||||
homepage: 'HomePage',
|
let a = document.createElement('a')
|
||||||
downloadlink: 'Download',
|
a.classList.add('goodlink')
|
||||||
vediotutorial: 'Vedio Tutorial',
|
a.classList.add('buttonsize')
|
||||||
contactme: 'Discord',
|
a.innerText = supportlangs[lang]
|
||||||
bit64link: '64-bit',
|
a.addEventListener('click', function () {
|
||||||
bit32link: '32-bit'
|
switchlang(lang)
|
||||||
}
|
})
|
||||||
}
|
document.getElementById('languageswitch').appendChild(a)
|
||||||
const languagelinks = {
|
|
||||||
contactme: {
|
|
||||||
zh: 'https://qm.qq.com/q/I5rr3uEpi2',
|
|
||||||
en: 'https://discord.com/invite/ErtDwVeAbB',
|
|
||||||
},
|
|
||||||
vediotutorial: {
|
|
||||||
zh: 'https://space.bilibili.com/592120404/video',
|
|
||||||
en: 'https://www.youtube.com/results?search_query=LunaTranslator',
|
|
||||||
},
|
|
||||||
homepage: {
|
|
||||||
zh: window.location.protocol + '//' + window.location.hostname.substring(5)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
function getcurrlang(url) {
|
function getcurrlang(url) {
|
||||||
for (let key in navitexts) {
|
for (let key in supportlangs) {
|
||||||
if (url.includes(`/${key}/`)) {
|
if (url.includes(`/${key}/`)) {
|
||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
@ -159,10 +191,14 @@ function switchlang(lang) {
|
|||||||
function browserlang() {
|
function browserlang() {
|
||||||
let l = navigator.language
|
let l = navigator.language
|
||||||
if (l.includes('-')) l = l.split('-')[0]
|
if (l.includes('-')) l = l.split('-')[0]
|
||||||
if (navitexts[l]) return l
|
if (supportlangs.includes(l)) return l
|
||||||
return 'en'
|
return 'en'
|
||||||
}
|
}
|
||||||
|
const titleids = ['homepage', 'downloadlink', 'vediotutorial', 'contactme', 'bit64link', 'bit32link']
|
||||||
|
|
||||||
|
|
||||||
window.onpopstate = function (event) {
|
window.onpopstate = function (event) {
|
||||||
|
|
||||||
let url = window.location.href;
|
let url = window.location.href;
|
||||||
if (url.endsWith('.redirect')) {
|
if (url.endsWith('.redirect')) {
|
||||||
window.location.href = url.substring(0, url.length - 9);
|
window.location.href = url.substring(0, url.length - 9);
|
||||||
@ -173,7 +209,7 @@ window.onpopstate = function (event) {
|
|||||||
window.location.href += lang + '/'
|
window.location.href += lang + '/'
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for (let key in navitexts) {
|
for (let key in supportlangs) {
|
||||||
if (url.endsWith(`/${key}/`)) {
|
if (url.endsWith(`/${key}/`)) {
|
||||||
window.location.href += 'README'
|
window.location.href += 'README'
|
||||||
return
|
return
|
||||||
@ -183,39 +219,19 @@ window.onpopstate = function (event) {
|
|||||||
window.localStorage.currentlang = thislang
|
window.localStorage.currentlang = thislang
|
||||||
if (thislang != currentlang) {
|
if (thislang != currentlang) {
|
||||||
currentlang = thislang
|
currentlang = thislang
|
||||||
|
titleids.forEach(key => {
|
||||||
for (let key in navitexts[currentlang]) {
|
document.getElementById(key).innerText = langs[key][currentlang]
|
||||||
document.getElementById(key).innerText = navitexts[currentlang][key]
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
document.getElementById('homepage').href = window.location.protocol + '//' + window.location.hostname.substring(5)
|
||||||
|
|
||||||
for (let _id in languagelinks) {
|
for (let _id in languagelinks) {
|
||||||
let link = languagelinks[_id][currentlang]
|
document.getElementById(_id).href = languagelinks[_id][currentlang]
|
||||||
if (link === undefined)
|
|
||||||
link = languagelinks[_id].zh
|
|
||||||
document.getElementById(_id).href = link
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function copyToClipboard(text) {
|
function copyToClipboard(text) {
|
||||||
let url = window.location.href;
|
|
||||||
let thislang = getcurrlang(url)
|
|
||||||
const langs = {
|
|
||||||
zh: {
|
|
||||||
ok: '已复制到剪贴板',
|
|
||||||
fail: '无法复制:',
|
|
||||||
},
|
|
||||||
en: {
|
|
||||||
ok: 'Copy to clipboard',
|
|
||||||
fail: 'Cannot copy:',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
navigator.clipboard.writeText(text).then(function () {
|
navigator.clipboard.writeText(text).then(function () {
|
||||||
showToast(langs[thislang].ok + '\n' + text);
|
showToast(langs.clipboardok[currentlang] + '\n' + text);
|
||||||
}, function (err) {
|
|
||||||
showToast(langs[thislang].fail + err);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
showtoastsig = null
|
showtoastsig = null
|
||||||
|
Loading…
x
Reference in New Issue
Block a user