NEW_CKEDITOR.plugins.add("language",{requires:"menubutton",lang:"ar,az,bg,ca,cs,cy,da,de,de-ch,el,en,en-au,en-gb,eo,es,es-mx,et,eu,fa,fi,fo,fr,gl,he,hr,hu,id,it,ja,km,ko,ku,lt,lv,nb,nl,no,oc,pl,pt,pt-br,ro,ru,sk,sl,sq,sr,sr-latn,sv,tr,tt,ug,uk,vi,zh,zh-cn",icons:"language",hidpi:!0,init:function(e){var t,n,a,r,l=e.config.language_list||["ar:Arabic:rtl","fr:French","es:Spanish"],g=this,u=e.lang.language,o={};for(e.addCommand("language",{allowedContent:"span[!lang,dir]",requiredContent:"span[lang]",contextSensitive:!0,exec:function(e,t){var n=o["language_"+t];n&&e[n.style.checkActive(e.elementPath(),e)?"removeStyle":"applyStyle"](n.style)},refresh:function(e){this.setState(g.getCurrentLangElement(e)?NEW_CKEDITOR.TRISTATE_ON:NEW_CKEDITOR.TRISTATE_OFF)}}),r=0;r<l.length;r++)n=(t=l[r].split(":"))[0],o[a="language_"+n]={label:t[1],langId:n,group:"language",order:r,ltr:"rtl"!=(""+t[2]).toLowerCase(),onClick:function(){e.execCommand("language",this.langId)},role:"menuitemcheckbox"},o[a].style=new NEW_CKEDITOR.style({element:"span",attributes:{lang:n,dir:o[a].ltr?"ltr":"rtl"}});o.language_remove={label:u.remove,group:"language_remove",state:NEW_CKEDITOR.TRISTATE_DISABLED,order:o.length,onClick:function(){var t=g.getCurrentLangElement(e);t&&e.execCommand("language",t.getAttribute("lang"))}},e.addMenuGroup("language",1),e.addMenuGroup("language_remove"),e.addMenuItems(o),e.ui.add("Language",NEW_CKEDITOR.UI_MENUBUTTON,{label:u.button,allowedContent:"span[!lang,dir]",requiredContent:"span[lang]",toolbar:"bidi,30",command:"language",contentTransformations:[[{element:"span",left:function(e){return e.attributes.lang&&(!e.attributes.dir||""===e.attributes.dir)},right:function(e){var t=NEW_CKEDITOR.tools.object.keys(NEW_CKEDITOR.lang.rtl);t=-1!==NEW_CKEDITOR.tools.array.indexOf(t,e.attributes.lang)?"rtl":"ltr",e.attributes.dir=t}}]],onMenu:function(){var t,n={},a=g.getCurrentLangElement(e);for(t in o)n[t]=NEW_CKEDITOR.TRISTATE_OFF;return n.language_remove=a?NEW_CKEDITOR.TRISTATE_OFF:NEW_CKEDITOR.TRISTATE_DISABLED,a&&(n["language_"+a.getAttribute("lang")]=NEW_CKEDITOR.TRISTATE_ON),n}}),e.addRemoveFormatFilter&&e.addRemoveFormatFilter((function(e){return!(e.is("span")&&e.getAttribute("dir")&&e.getAttribute("lang"))}))},getCurrentLangElement:function(e){var t,n=e.elementPath();if(e=n&&n.elements,n)for(var a=0;a<e.length;a++)n=e[a],!t&&"span"==n.getName()&&n.hasAttribute("lang")&&(t=n);return t}});