Matías Cánepa
Matías Cánepa

Reputation: 5974

change language value in CKEditor

I'm trying to change a value of my language definition. I need to do this where the editor instances are created and under certain conditions.

I don't want to change the language file because that file is fine the way it is and also because other editors on the same website doesn't need that particular modification.

Can some one help me? I'm using 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);            
});

Upvotes: 2

Views: 1585

Answers (1)

oleq
oleq

Reputation: 15895

Modify the code of the format plugin, by adding beforeInit function:

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

In this function you can modify all the language entries as labels and stuff are generated, inserted and displayed in the init() below. You can use any kind of condition to change the lang entry here.


Another solution: harder but global. With this you can overwrite all plugins from one place, without touching source codes:

// 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 );
};

Upvotes: 1

Related Questions