diff --git a/frontend/docusaurus.config.ts b/frontend/docusaurus.config.ts index 5d9ab873656..b73056e1b11 100644 --- a/frontend/docusaurus.config.ts +++ b/frontend/docusaurus.config.ts @@ -14,7 +14,6 @@ const copyrightByLocale: Record = { "zh-CN": `版权所有 © ${currentYear} open.mp。基于Docusaurus构建。`, tr: `Telif Hakkı © ${currentYear} open.mp. Docusaurus ile yapıldı.`, fa: `حق نشر © ${currentYear} open.mp. ساخته شده با Docusaurus.`, - }; const config: Config = { @@ -236,6 +235,55 @@ const config: Config = { ], ], + headTags: [ + { + tagName: "script", + attributes: {}, + innerHTML: ` +(function() { + var locales = ["en","es","ru","ar","bs","de","fil","fr","fa","hu","id","it","nl","pl","pt-BR","ro","sl","sr","ta","th","tr","uk","vi","zh-CN","zh-TW"]; + var path = window.location.pathname; + var firstSegment = path.split("/")[1]; + + if(locales.indexOf(firstSegment) !== -1) { + localStorage.setItem("omp-locale", firstSegment); + return; + } + + var saved = localStorage.getItem("omp-locale"); + + if(saved && saved !== "en") { + window.location.href = "/" + saved + path + window.location.search + window.location.hash; + return; + } + + if(saved === "en") return; + + var navLang = (navigator.language || navigator.userLanguage || "en").toLowerCase(); + + var map = { + "pt": "pt-BR", "pt-br": "pt-BR", + "zh": "zh-CN", "zh-cn": "zh-CN", "zh-tw": "zh-TW", + "zh-hans": "zh-CN", "zh-hant": "zh-TW" + }; + + var target = map[navLang] || navLang; + + if(locales.indexOf(target) === -1 && navLang.indexOf("-") !== -1) { + target = navLang.split("-")[0]; + } + + if(locales.indexOf(target) !== -1 && target !== "en") { + localStorage.setItem("omp-locale", target); + window.location.href = "/" + target + path + window.location.search + window.location.hash; + } else { + localStorage.setItem("omp-locale", "en"); + } +})(); + `, + }, + ], + themeConfig: { // Replace with your project's social card image: "images/assets/wordmark-coloured-bg.png", @@ -367,10 +415,10 @@ const config: Config = { // Optional: see doc section below contextualSearch: true, - // Optional: path for search page that enabled by default (`false` to disable it) + // Optional: path for search page that enabled by default (\`false\` to disable it) searchPagePath: "search", - // Optional: whether the insights feature is enabled or not on Docsearch (`false` by default) + // Optional: whether the insights feature is enabled or not on Docsearch (\`false\` by default) insights: false, }, colorMode: {