Search code examples
javascriptjquerypluginsckeditorfckeditor

Change tooltip language of custom plugin Ckedtior


I have made a custom plugin for ckeditor, now i am trying to change the tooltip language dynamically on selected language. I have tried to put the translated tooltip text in corresponding js file in lang folder of ckeditor but it is not working.


Solution

  • If you create a toolbar button, add it with editor.ui.addButton within plugin's pluginDefinition.init, like this:

    CKEDITOR.plugins.add( 'pluginName', {
        lang: 'lan,gua,ges,sup,por,ted,by,this,plu,gin,com,ma,se,pa,ra,ted',
        icons: 'icons,used,by,this,plugin',
        requires: 'anotherPlugin',
        init: function( editor ) {
            // Register the toolbar button.
            if ( editor.ui.addButton ) {
                editor.ui.addButton( 'ButtonName', {
                    label: editor.lang.pluginName.labelName, // Your label
                    command: 'yourcommand', // Command name
                    directional: true, // Depends on BiDi support, optional
                    toolbar: 'list,10' // Wherever you want, in fact
                });             
            }
            ...
         }
     });
    

    Now supposing your language is foo, then pluginName/lang/foo.js should look like this:

    CKEDITOR.plugins.setLang( 'pluginName', 'foo', {
        labelName: 'My label!'
    });
    

    Remember to add foo to the lang property inside of the object literal of your pluginDefinition:

    CKEDITOR.plugins.add( 'pluginName', {
        lang: 'foo',
        ...
     });
    

    Generally speaking, editor.lang.pluginName.labelName is available inside of init, whatever you want to use it for.