Inline translate Chrome Bug?
-
16-10-2019 - |
문제
Maybe it's just me, but in Chrome browser inline translate does not work. The red boxes are shown and if I hover the mouse the book icon appears but if I click it nothing happens. I had the same problem on different servers.
Other browser like Firefox and IE are fine.
Is there a bugfix for this?
해결책
Yes, the inline translation feature is broken in Google Chrome. Back when the inline translation feature was originally developed, Magento made use of a non-standard translate
attribute in DOM elements to flag translatable text.
Since then, Google Chrome has a feature where a default translate
property is added to every DOM node available in javascript (over simplification).
This, in turn, interfers with Magento's PrototypeJS xpath code used to implement the translation feature. Specifically, this
if (!$(target).match('*[translate]')) {
target = target.up('*[translate]');
}
I solution I came up with last year was to add the following bit of javascript to every page when inline translations are active.
if(Object.__defineGetter__)
{
var hasTranslateAttribute = function(){
return $(this).hasAttribute("translate");
};
document.observe("dom:loaded", function() {
$$('*').each(function(theElement){
theElement.__defineGetter__("translate", hasTranslateAttribute);
});
});
}
다른 팁
For Enterprise customers, there is a Magento core patch available (SUPEE-1373) which was tested by us and works.
It basically replaces all the translate
properties by data-translate
across the code.
The solution provided by Alan Storm works. To make it work across the entire site, just add the snippet to /app/code/core/Mage/Core/Model/Translate/Inline.php, right after
<script type="text/javascript">
new TranslateInline('translate-inline-trig', '<?php echo $ajaxUrl ?>', '<?php
echo Mage::getDesign()->getArea() ?>');
That's line 278 in 1.7.