简体   繁体   English

如何指定 CKEditor(jquery 版本)的界面语言?

[英]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.我尝试阅读 CKEditor 帮助站点,但它不是很有帮助。

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.如果您使用自定义配置文件来创建 CKEditor 实例,请尝试此操作。

配置

Untested, but check this out:未经测试,但请检查:

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


Q. How do i set language for CKEditor for achieving localization? Q. 如何设置 CKEditor 的语言以实现本地化?

A. Use language property for setting the language of CKEditor. A. 使用language 属性设置CKEditor 的语言。 By using this property CKEditor menu's and labels will display the localized language.通过使用此属性,CKEditor 菜单和标签将显示本地化语言。

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

And if you are using custom config file for creating CKEditor instance use,如果您使用自定义配置文件来创建 CKEditor 实例使用,

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

Even one can use javascript variable to set language file to make localization option dynamic.甚至可以使用 javascript 变量来设置语言文件,使本地化选项动态化。

I found an easy way to set up your language to CKE 4 editor :我找到了一种将您的语言设置为CKE 4编辑器的简单方法:

 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.要更改我使用的编辑器的语言ajax ,以获取当前选择的语言。 Here is the code which I added in config.js :这是我在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 ):这是另一个示例(基于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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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