javascript - CK编辑器4,谷歌翻译也翻译我的MATHJAX公式,即使没有翻译

标签 javascript google-translate mathjax ckeditor4.x google-translation-api

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

我正在使用 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>

到这里为止一切都很顺利。

现在,当我发布数据并使用谷歌翻译将数据从英语翻译成印地语时,如下所示

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.

我尝试了很多其他替代方案,但没有一个有效,请帮我解决这个问题。

最佳答案

这已出现在 MathJax issue tracker 中。看来php google translate似乎无法处理 notranslate 类。您可以向他们提交错误。

与此同时,数学“翻译”后的主要问题是反斜杠后面有多余的空格。因此,也许只需进行正则表达式替换,将反斜杠后跟空格转换为反斜杠即可?

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

关于javascript - CK编辑器4,谷歌翻译也翻译我的MATHJAX公式,即使没有翻译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60221267/

相关文章:

javascript - 谷歌地图 JS : How do I get the small tooltip marker on hover AND the normal info window on click?

javascript - Twitter Bootstrap 工具提示不起作用

google-translate - Google translate API V2 的速率限制是多少?

javascript - React 绑定(bind)到 ReactDOM 之外的 HTML 元素

haskell - MathJax 使用 Pandoc 库

android - 在 Web View 中呈现包含数学方程式的 HTML 数据

javascript - Uploadcare 上传图像输入未使用 Meteor 显示

javascript - 如何轻松地将图像置于 DIV 中心?

javascript - JavaScript 中如何给变量赋值

php - 将(不翻译)波斯语字母转换为英文字母,如 PHP 中的谷歌翻译