Andrey Fedoseev
Andrey Fedoseev

Reputation: 5382

How to change item names in CKEditor "Format" menu?

I need to change the option names in the "Format" menu in CKEditor. For instance, I want to change "Normal" to "Paragraph".

I understand that one way to do it is to edit the language file (en.js). But I don't want to mess up the original sourcecode because it will make the upgrade to a future version much harder.

I tried to change the value CKEDITOR.lang.en.tag_p at runtime before initializing the editor:

CKEDITOR.lang.en.tag_p = "Paragraph";
CKEDITOR.replace(...);

It didn't work because the language file is not loaded at this point (lang.en is undefined).

I also tried to use event handlers (instanceLoaded and loaded) - no success.

Changing the language values on instanceLoaded seems to be too late. It still shows the default values in the menu.

And loaded event never fires for some reason.

I found a solution that involves overriding CKEDITOR.plugins.load, but I think it's too much for such a simple task.

Is there a simple and elegant way to do that?

Upvotes: 2

Views: 193

Answers (1)

Andrey Fedoseev
Andrey Fedoseev

Reputation: 5382

I found the following solution: load the English language file before creating editor instance, and update it using callback once it is loaded.

CKEDITOR.lang.load("en", "en", function() {
  CKEDITOR.lang.en.format.tag_p = "Paragraph";
  CKEDITOR.lang.en.format.tag_h2 = "Header";
  CKEDITOR.lang.en.format.tag_h3 = "Sub-Header";
});
// Init editor here

I personally don't like it, but it's the best I could do.

Upvotes: 3

Related Questions