简体   繁体   中英

How do I specify the interface language for CKEditor (jquery version)?

My code atm is this simple:

$(document).ready(function(){
   $('textarea').ckeditor();
});

It works flawlessly, I just need to add one more thing: I need to specify the interface language (localisation). I tried reading the CKEditor help site, but it isn't very helpful.

Can anyone tell me where and how do I add any code to specify the language?

尝试这个:

$('textarea').ckeditor({language: 'de'});

If you are using custom config file for creating CKEditor instance try this.

配置

Untested, but check this out:

http://www.sayopenweb.com/ckeditor-faq/


Q. How do i set language for CKEditor for achieving localization?

A. Use language property for setting the language of CKEditor. By using this property CKEditor menu's and labels will display the localized language.

CKEditor.replace('divcomponentid', {
        language: 'ja'
})

And if you are using custom config file for creating CKEditor instance use,

CKEditor.editorConfig = function(config) {
    language = "ja";
};

Even one can use javascript variable to set language file to make localization option dynamic.

I found an easy way to set up your language to CKE 4 editor :

 1. Go to config.js -> 
 2. Then change this line in config.js ->
 3. config.language = "en"

We have a multilingual portal and it is possible to change the language of whole interface. To change the language of the editor I am using ajax , to get the currently selected language. Here is the code which I added in config.js :

CKEDITOR.editorConfig = function(config) {
    var strLanguageName = "en";
    jQuery.ajaxSetup({ async: false, cache: false });
    jQuery.ajax({
        type: "POST",
        url: "/remotemethods/getCurrentLang",
        data: "xml",
        success: setLanguage,
        error: onError
    });
    function setLanguage(data) {
        strLanguageName = jQuery(data).find("lang").text();
    }
    function onError(xhr, ajaxOptions, thrownError) { }
    config.language = strLanguageName;
};

Here is one more example (based on CKEditor5 ):

 let theEditor; ClassicEditor .create(document.querySelector('#editor'), { // The language code is defined in the https://en.wikipedia.org/wiki/ISO_639-1 standard. language: 'sk' }) .then(editor => { theEditor = editor; }) .catch(error => { console.error(error); });
 <script src="https://cdn.ckeditor.com/ckeditor5/11.2.0/classic/ckeditor.js"></script> <script src="https://cdn.ckeditor.com/ckeditor5/11.2.0/classic/translations/sk.js"></script> <textarea name="content" id="editor">This is some sample content.</textarea>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM