parent
26078de552
commit
0986bbfd4f
@ -1,6 +1,9 @@ |
|||||||
/** This JS will be included when loading an HTML in the Document tool */ |
import { createPinia, setActivePinia } from 'pinia' |
||||||
|
|
||||||
import translateHtml from './../translatehtml.js'; |
const pinia = createPinia() |
||||||
|
setActivePinia(pinia) |
||||||
|
|
||||||
|
import translateHtml from './../translatehtml.js' |
||||||
document.addEventListener('DOMContentLoaded', function () { |
document.addEventListener('DOMContentLoaded', function () { |
||||||
translateHtml(); |
translateHtml() |
||||||
}); |
}); |
||||||
|
@ -1,51 +1,56 @@ |
|||||||
/* For licensing terms, see /license.txt */ |
/* For licensing terms, see /license.txt */ |
||||||
|
|
||||||
import { usePlatformConfig } from "../vue/store/platformConfig"; |
import { usePlatformConfig } from "../vue/store/platformConfig" |
||||||
|
|
||||||
function normalizeLocale(locale) { |
function normalizeLocale(locale) { |
||||||
return locale.split('_')[0]; |
return locale.split('_')[0] |
||||||
} |
} |
||||||
|
|
||||||
export default function translateHtml() { |
export default async function translateHtml() { |
||||||
const platformConfigStore = usePlatformConfig(); |
try { |
||||||
|
const platformConfigStore = usePlatformConfig() |
||||||
|
await platformConfigStore.initialize() |
||||||
|
|
||||||
if ( |
if ( |
||||||
window.user && |
window.user && |
||||||
window.user.locale && |
window.user.locale && |
||||||
"true" === platformConfigStore.getSetting("editor.translate_html") |
"true" === platformConfigStore.getSetting("editor.translate_html") |
||||||
) { |
) { |
||||||
var isoCode = normalizeLocale(window.user.locale); |
var isoCode = normalizeLocale(window.user.locale) |
||||||
const translateElement = document.querySelector(".mce-translatehtml"); |
const translateElement = document.querySelector(".mce-translatehtml") |
||||||
if (translateElement) { |
if (translateElement) { |
||||||
document.querySelectorAll(".mce-translatehtml").forEach(function (el) { |
document.querySelectorAll(".mce-translatehtml").forEach(function (el) { |
||||||
el.style.display = "none"; |
el.style.display = "none" |
||||||
}); |
}) |
||||||
const selectedLang = document.querySelectorAll(`[lang="${isoCode}"]`); |
const selectedLang = document.querySelectorAll(`[lang="${isoCode}"]`) |
||||||
if (selectedLang.length > 0) { |
if (selectedLang.length > 0) { |
||||||
selectedLang.forEach(function (userLang) { |
selectedLang.forEach(function (userLang) { |
||||||
userLang.classList.remove("hidden"); |
userLang.classList.remove("hidden") |
||||||
userLang.style.display = "block"; |
userLang.style.display = "block" |
||||||
}); |
}) |
||||||
|
} |
||||||
} |
} |
||||||
} |
|
||||||
|
|
||||||
// it checks content from old version
|
// it checks content from old version
|
||||||
const langSpans = document.querySelectorAll('span[lang]'); |
const langSpans = document.querySelectorAll('span[lang]') |
||||||
const langs = [...langSpans].filter(span => !span.classList.contains('mce-translatehtml')); |
const langs = [...langSpans].filter(span => !span.classList.contains('mce-translatehtml')) |
||||||
|
|
||||||
if (langs.length > 0) { |
if (langs.length > 0) { |
||||||
// it hides all contents with lang
|
// it hides all contents with lang
|
||||||
langs.forEach(function (el) { |
langs.forEach(function (el) { |
||||||
el.style.display = "none"; |
el.style.display = "none" |
||||||
}); |
}) |
||||||
|
|
||||||
const selectedLang = document.querySelectorAll(`span[lang="${isoCode}"]`); |
const selectedLang = document.querySelectorAll(`span[lang="${isoCode}"]`) |
||||||
if (selectedLang.length > 0) { |
if (selectedLang.length > 0) { |
||||||
selectedLang.forEach(function (userLang) { |
selectedLang.forEach(function (userLang) { |
||||||
userLang.classList.remove("hidden"); |
userLang.classList.remove("hidden") |
||||||
userLang.style.display = "block"; |
userLang.style.display = "block" |
||||||
}); |
}) |
||||||
|
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
} catch (error) { |
||||||
|
console.error("Error in translateHtml:", error) |
||||||
} |
} |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue