更改CKEditor中的语言值

change language value in CKEditor

本文关键字:语言 CKEditor 更改      更新时间:2023-09-26

我正在尝试更改语言定义的值。我需要在创建编辑器实例的地方以及在特定条件下执行此操作。

我不想更改语言文件,因为该文件是正常的,也因为同一网站上的其他编辑不需要进行特定的修改。

有人能帮我吗?我正在使用CKEDITOR 3.6.1

$("form textarea").each(function()
{
    var name = $(this).attr("name");
    var instance = CKEDITOR.instances[name];
    if(instance)
    {
        CKEDITOR.instances[name].destroy(true)
    }
    CKEDITOR.config.format_tags = 'h1;p';
    CKEDITOR.config.format_p = { element : 'p', attributes : { 'class' : 'my_class' } };
    //if(condition) CKEDITOR.config.lang.es.tag_h1 = "My special header";
    //if(condition) CKEDITOR.lang.es.tag_h1 = "My special header";
    CKEDITOR.replace(name);            
});

通过添加beforeInit函数修改格式插件的代码:

CKEDITOR.plugins.add( 'format', {
    requires: 'richcombo',
    beforeInit: function( editor ) {
        editor.lang.format.tag_h1 = 'Moooooooo!';
    },
    init: function( editor ) {
        ...

在这个函数中,您可以修改所有的语言条目,因为标签和内容会在下面的init()中生成、插入和显示。您可以使用任何类型的条件来更改此处的lang条目。


另一个解决方案:更难,但全球化。有了这个,你可以从一个地方覆盖所有插件,而无需接触源代码:

// Save the old CKEDITOR.plugins.load
var orgLoad = CKEDITOR.plugins.load;
// Overwrite CKEDITOR.plugins.load
CKEDITOR.plugins.load = function() {
    // Save the old callback argument.
    var oldCallback = arguments[ 1 ];
    // Overwrite the old callback argument.
    arguments[ 1 ] = function( plugins ) {
        // Modify the plugin by adding beforeInit to the definition.
        plugins.format.beforeInit = function( editor ) {
            editor.lang.format.tag_h1 = 'Moooooooo!';
        };
        // Call the old callback.
        oldCallback.call( this, plugins );
    };
    // Call old CKEDITOR.plugins.load
    orgLoad.apply( this, arguments );
};