【发布时间】:2020-05-29 22:54:30
【问题描述】:
大家好,我这里有个大问题很久没有解决。
我正在使用 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);
我知道 math-tex 类中存在双引号问题,但是 这就是我从ckeditor 得到的。即使我替换双引号 单它不能完成这项工作。我也尝试过将 notranslate 类与 math-tex 一起使用,它仍然无法正常工作。
我尝试了其他替代方法,但都没有效果,请帮我解决这个问题。
【问题讨论】:
标签: javascript google-translate mathjax ckeditor4.x google-translation-api