You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.8 KiB
61 lines
1.8 KiB
/* For licensing terms, see /license.txt */
|
|
|
|
import { usePlatformConfig } from "../vue/store/platformConfig";
|
|
|
|
export default function translateHtml() {
|
|
const platformConfigStore = usePlatformConfig();
|
|
|
|
if (
|
|
window.user &&
|
|
window.user.locale &&
|
|
"true" === platformConfigStore.getSetting("editor.translate_html")
|
|
) {
|
|
var isoCode = window.user.locale;
|
|
const translateElement = document.querySelector(".mce-translatehtml");
|
|
if (translateElement) {
|
|
document.querySelectorAll(".mce-translatehtml").forEach(function (el) {
|
|
el.style.display = "none";
|
|
});
|
|
const selectedLang = document.querySelectorAll(
|
|
'[lang="' + isoCode + '"]'
|
|
);
|
|
if (selectedLang.length > 0) {
|
|
selectedLang.forEach(function (userLang) {
|
|
userLang.classList.remove("hidden");
|
|
userLang.style.display = "block";
|
|
});
|
|
}
|
|
}
|
|
|
|
// it checks content from old version
|
|
const langSpans = document.querySelectorAll('span[lang]');
|
|
const langs = [...langSpans].filter(span => !span.classList.contains('mce-translatehtml'));
|
|
|
|
if (langs.length > 0) {
|
|
// it hides all contents with lang
|
|
langs.forEach(function (el) {
|
|
el.style.display = "none";
|
|
});
|
|
|
|
// To show only the content by user language.
|
|
if (isoCode == "pl_PL") {
|
|
isoCode = "pl";
|
|
}
|
|
if (isoCode == "fr_FR") {
|
|
isoCode = "fr";
|
|
}
|
|
if (isoCode == "en_US") {
|
|
isoCode = "en";
|
|
}
|
|
const selectedLang = document.querySelectorAll(
|
|
'span[lang="' + isoCode + '"]'
|
|
);
|
|
if (selectedLang.length > 0) {
|
|
selectedLang.forEach(function (userLang) {
|
|
userLang.classList.remove("hidden");
|
|
userLang.style.display = "block";
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|