Создайте «Блок/Меню» и разместите его на страницах, где включен поисковый фильтр.
Например в пункте «Введите символы, при обнаружении которых отображать Блок/Меню:» укажите:
/ua/shop/
/ua/pers_shop/
Пример перевода строк, а также кнопки «Применить».
<script>
(function() {
const $dict = {
"Color": "Колір",
"Blue": "Синій",
"Green": "Зелений",
"Black": "Чорний"
};
/*
Example translations:
RU: "Color": "Цвет", "Blue": "Синий", "Green": "Зеленый", "Black": "Черный"
UA: "Color": "Колір", "Blue": "Синій", "Green": "Зелений", "Black": "Чорний"
PL: "Color": "Kolor", "Blue": "Niebieski", "Green": "Zielony", "Black": "Czarny"
*/
const applyTranslations = () => {
Object.entries($dict).forEach(([txtorig, txtnew]) => {
const selectors = [
`#shop_catalog_product_types_id_ajax .product_types_valuebox_checkbox span`,
`#shop_catalog_product_types_id_ajax .shop_catalog_product_types_block_title`,
`.shop_catalog_product_properties_block .shop_catalog_product_types_block_title`,
`.shop_catalog_product_properties_block .product_types_valuebox_checkbox`
];
selectors.forEach(selector => {
document.querySelectorAll(selector).forEach(el => {
if (el.textContent.includes(txtorig)) {
el.innerHTML = txtnew;
}
});
});
});
};
applyTranslations();
const target = document.getElementById(`shop_catalog_product_types_id_ajax`);
if (target) {
const observer = new MutationObserver(() => {
observer.disconnect();
applyTranslations();
observer.observe(target, { childList: true, subtree: true });
});
observer.observe(target, { childList: true, subtree: true });
}
setTimeout(() => {
const smartSearchInput = document.querySelector(`.hotengine-smart_search_submit_button input`);
if (smartSearchInput) smartSearchInput.value = "Застосувати";
const searchInpButton = document.querySelector(`#searchinp_smart_search .button`);
if (searchInpButton) searchInpButton.value = "Застосувати";
}, 100);
})();
</script>
Пример перевода с перезаписью слов:
<script>
(function() {
const $dict = {
"Colour": "Farbe",
"Blue": "Blau",
"Green": "Grün",
"Black": "Schwarz"
};
/*
Example translations:
RU: "Colour": "Цвет", "Blue": "Синий", "Green": "Зеленый", "Black": "Черный"
UA: "Colour": "Колір", "Blue": "Синій", "Green": "Зелений", "Black": "Чорний"
PL: "Colour": "Kolor", "Blue": "Niebieski", "Green": "Zielony", "Black": "Czarny"
*/
const applyTranslations = (container) => {
Object.entries($dict).forEach(([txtorig, txtnew]) => {
const regex = new RegExp(txtorig, "g");
if (container.innerHTML.includes(txtorig)) {
container.innerHTML = container.innerHTML.replace(regex, txtnew);
}
});
};
const target = document.getElementById(`shop_catalog_product_types_id_ajax`);
if (target) {
applyTranslations(target);
const observer = new MutationObserver(() => {
observer.disconnect();
applyTranslations(target);
observer.observe(target, { childList: true, subtree: true });
});
observer.observe(target, { childList: true, subtree: true });
}
setTimeout(() => {
const smartSearchInput = document.querySelector(`.hotengine-smart_search_submit_button input`);
if (smartSearchInput) smartSearchInput.value = "Anwenden";
const searchInpButton = document.querySelector(`#searchinp_smart_search .button`);
if (searchInpButton) searchInpButton.value = "Anwenden";
}, 100);
})();
</script>
Аналогично, вы можете добавить другие языки и новые слова, размещая код на соответствующие языковые версии сайта.