From cf4762e8444852fd611a480ad4d0d69ff06c6f8c Mon Sep 17 00:00:00 2001 From: Crazy ArKzX Date: Sun, 2 Aug 2026 13:35:49 -0300 Subject: [PATCH 1/4] Add locale handling script to Docusaurus config Automatic Language Detection --- frontend/docusaurus.config.ts | 48 ++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/frontend/docusaurus.config.ts b/frontend/docusaurus.config.ts index 5d9ab873656..c705c67ef1d 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,53 @@ 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.replace("/" + 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.replace("/" + 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", From 209d93ae2dccbf16b42d158e444913f442e82874 Mon Sep 17 00:00:00 2001 From: Crazy ArKzX Date: Sun, 2 Aug 2026 16:05:39 -0300 Subject: [PATCH 2/4] Refactor locale handling and update comments --- frontend/docusaurus.config.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/frontend/docusaurus.config.ts b/frontend/docusaurus.config.ts index c705c67ef1d..a2635cda4ec 100644 --- a/frontend/docusaurus.config.ts +++ b/frontend/docusaurus.config.ts @@ -244,12 +244,14 @@ const config: Config = { 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; } - + + localStorage.setItem("omp-locale", "en"); + var saved = localStorage.getItem("omp-locale"); if(saved && saved !== "en") { window.location.replace("/" + saved + path + window.location.search + window.location.hash); @@ -258,19 +260,19 @@ const config: Config = { 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.replace("/" + target + path + window.location.search + window.location.hash); @@ -413,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: { From 1f9c142c447fc49f88f9b2a9279c40628f6a1b8a Mon Sep 17 00:00:00 2001 From: Crazy ArKzX Date: Sun, 2 Aug 2026 16:27:37 -0300 Subject: [PATCH 3/4] Refactor locale handling in docusaurus.config.ts --- frontend/docusaurus.config.ts | 76 +++++++++++++++++------------------ 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/frontend/docusaurus.config.ts b/frontend/docusaurus.config.ts index a2635cda4ec..f112671250f 100644 --- a/frontend/docusaurus.config.ts +++ b/frontend/docusaurus.config.ts @@ -241,44 +241,44 @@ const config: Config = { 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; - } - - localStorage.setItem("omp-locale", "en"); - - var saved = localStorage.getItem("omp-locale"); - if(saved && saved !== "en") { - window.location.replace("/" + 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.replace("/" + target + path + window.location.search + window.location.hash); - } else { - localStorage.setItem("omp-locale", "en"); - } + 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.replace("/" + 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.replace("/" + target + path + window.location.search + window.location.hash); + } else { + localStorage.setItem("omp-locale", "en"); + } })(); `, }, From 63090a538312ad70b20e5b25a4df52fc056dda7f Mon Sep 17 00:00:00 2001 From: Crazy ArKzX Date: Sun, 2 Aug 2026 16:48:46 -0300 Subject: [PATCH 4/4] Change window.location.replace to window.location.href --- frontend/docusaurus.config.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/docusaurus.config.ts b/frontend/docusaurus.config.ts index f112671250f..b73056e1b11 100644 --- a/frontend/docusaurus.config.ts +++ b/frontend/docusaurus.config.ts @@ -253,7 +253,7 @@ const config: Config = { var saved = localStorage.getItem("omp-locale"); if(saved && saved !== "en") { - window.location.replace("/" + saved + path + window.location.search + window.location.hash); + window.location.href = "/" + saved + path + window.location.search + window.location.hash; return; } @@ -275,7 +275,7 @@ const config: Config = { if(locales.indexOf(target) !== -1 && target !== "en") { localStorage.setItem("omp-locale", target); - window.location.replace("/" + target + path + window.location.search + window.location.hash); + window.location.href = "/" + target + path + window.location.search + window.location.hash; } else { localStorage.setItem("omp-locale", "en"); }