CK editor 4, google 翻译也翻译我的 MATHJAX 公式,即使没有翻译

CK editor 4, google Translate also translate my MATHJAX formulas, even after no translate

大家好,我这里有一个大问题,很长一段时间都没有得到解决。

我正在使用 ck 编辑器和 Mathjax 插件像这样添加数学公式

<script src="https://cdn.ckeditor.com/4.13.1/standard-all/ckeditor.js"></script>

<textarea name="desc" class="form-control" id="richtext" placeholder="About this category."></textarea>

<script>

var richtext = document.getElementById('richtext');
CKEDITOR.replace('richtext', {
      on : {
            change: function ( evt )  {
            $(richtext).html(evt.editor.getData().replace(/(\r\n|\n|\r)/gm,"") ) ;
            }
        },
      extraPlugins: 'mathjax,colorbutton,font,justify,print,tableresize,uploadimage,uploadfile,pastefromword,liststyle,pagebreak',
      mathJaxLib: 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML',
      height: 320
    });

    if (CKEDITOR.env.ie && CKEDITOR.env.version == 8) {
      document.getElementById('ie8-warning').className = 'tip alert';
    }
                </script>

到这里为止一切正常。

现在,当我发布数据并使用 google translate 将数据从英语翻译成印地语时,就像这样

require_once ('assets/vendor/autoload.php');
use \Statickidz\GoogleTranslate;
$source = 'en';
$target = 'hi';
$text = "<p>This is a test question. please do not translate this <span class="math-tex">\(x = {-b \pm \sqrt{b^2-4ac} \over 2a}\)</span>equation.</p>";  
// i know there is an issue of double quotes in the class math-tex, but this is what i get from ckeditor. even if i replace the double quotes with single it does not does the job.

$tex4444t=str_replace(array("\r\n", "\r", "\n"), " ", $text);
$trans232 = new GoogleTranslate();
$results3 = $trans232->translate($source, $target, $tex4444t);

i know there is an issue of double quotes in the class math-tex, but this is what i get from ckeditor. even if i replace the double quotes with single it does not does the job. i have also tried using notranslate class with math-tex it still does not work.

我已经尝试过其他替代方案,但 none 有效,请帮我解决这个问题。

这已经出现在 MathJax issue tracker. It appears that php google translate 似乎无法处理 notranslate class。您可以向他们提交错误。

与此同时,"translated" 后数学的主要问题是反斜杠后有额外的 space。因此,也许只需要进行正则表达式替换,将反斜杠后跟 space 转换为反斜杠即可?

MathJax 问题跟踪器中还建议 another option 更复杂,但可能是最安全的方法。

$text=str_replace('"', "'",$formula_text)
$results=str_replace("\ ","\",$text);

这解决了问题