diff --git a/core/modules/ckeditor5/js/ckeditor5.es6.js b/core/modules/ckeditor5/js/ckeditor5.es6.js index e41d911c1f012b6bee06261c546ee516e120dcfc..e6916bc443e42d57eb26538c5c5925b8a6793064 100644 --- a/core/modules/ckeditor5/js/ckeditor5.es6.js +++ b/core/modules/ckeditor5/js/ckeditor5.es6.js @@ -367,25 +367,22 @@ */ attach(element, format) { const { editorClassic } = CKEditor5; - const { - toolbar, - plugins, - config: pluginConfig, - language, - } = format.editorSettings; + const { toolbar, plugins, config, language } = format.editorSettings; const extraPlugins = selectPlugins(plugins); - - const config = { + const pluginConfig = processConfig(config); + const editorConfig = { extraPlugins, toolbar, - language, - ...processConfig(pluginConfig), + ...pluginConfig, + // Language settings have a conflict between the editor localization + // settings and the "language" plugin. + language: { ...pluginConfig.language, ...language }, }; // Set the id immediately so that it is available when onChange is called. const id = setElementId(element); const { ClassicEditor } = editorClassic; - ClassicEditor.create(element, config) + ClassicEditor.create(element, editorConfig) .then((editor) => { // Save a reference to the initialized instance. Drupal.CKEditor5Instances.set(id, editor); diff --git a/core/modules/ckeditor5/js/ckeditor5.js b/core/modules/ckeditor5/js/ckeditor5.js index ef697a63951dda6bb96a439f07c897a99cba3773..ed479c324d5b8e6dfa90a150ef29988c94e22fa2 100644 --- a/core/modules/ckeditor5/js/ckeditor5.js +++ b/core/modules/ckeditor5/js/ckeditor5.js @@ -195,19 +195,21 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len var _format$editorSetting = format.editorSettings, toolbar = _format$editorSetting.toolbar, plugins = _format$editorSetting.plugins, - pluginConfig = _format$editorSetting.config, + config = _format$editorSetting.config, language = _format$editorSetting.language; var extraPlugins = selectPlugins(plugins); + var pluginConfig = processConfig(config); - var config = _objectSpread({ + var editorConfig = _objectSpread(_objectSpread({ extraPlugins: extraPlugins, - toolbar: toolbar, - language: language - }, processConfig(pluginConfig)); + toolbar: toolbar + }, pluginConfig), {}, { + language: _objectSpread(_objectSpread({}, pluginConfig.language), language) + }); var id = setElementId(element); var ClassicEditor = editorClassic.ClassicEditor; - ClassicEditor.create(element, config).then(function (editor) { + ClassicEditor.create(element, editorConfig).then(function (editor) { Drupal.CKEditor5Instances.set(id, editor); if (element.hasAttribute('required')) { diff --git a/core/modules/ckeditor5/tests/src/FunctionalJavascript/LanguageTest.php b/core/modules/ckeditor5/tests/src/FunctionalJavascript/LanguageTest.php index 88d3d0fee00bfbb352a497b19eb3e5bfd66ad193..40730f740779ef9933b98af95f7594c31b062968 100644 --- a/core/modules/ckeditor5/tests/src/FunctionalJavascript/LanguageTest.php +++ b/core/modules/ckeditor5/tests/src/FunctionalJavascript/LanguageTest.php @@ -29,18 +29,20 @@ class LanguageTest extends CKEditor5TestBase { * * @param string $langcode * The language code. - * @param string $blockquote_translation - * The expected translation for blockquote toolbar button. + * @param string $toolbar_item_name + * The CKEditor 5 plugin to enable. + * @param string $toolbar_item_translation + * The expected translation for CKEditor 5 plugin toolbar button. * * @dataProvider provider */ - public function test(string $langcode, string $blockquote_translation): void { + public function test(string $langcode, string $toolbar_item_name, string $toolbar_item_translation): void { $page = $this->getSession()->getPage(); $assert_session = $this->assertSession(); $this->createNewTextFormat($page, $assert_session); - $this->assertNotEmpty($assert_session->waitForElement('css', '.ckeditor5-toolbar-item-blockQuote')); - $this->triggerKeyUp('.ckeditor5-toolbar-item-blockQuote', 'ArrowDown'); + $this->assertNotEmpty($assert_session->waitForElement('css', ".ckeditor5-toolbar-item-$toolbar_item_name")); + $this->triggerKeyUp(".ckeditor5-toolbar-item-$toolbar_item_name", 'ArrowDown'); $assert_session->assertWaitOnAjaxRequest(); $this->saveNewTextFormat($page, $assert_session); @@ -50,7 +52,7 @@ public function test(string $langcode, string $blockquote_translation): void { $this->drupalGet('node/add'); $this->assertNotEmpty($assert_session->waitForElement('css', '.ck-editor')); // Ensure that blockquote button is translated. - $assert_session->elementExists('xpath', "//span[text()='$blockquote_translation']"); + $assert_session->elementExists('xpath', "//span[text()='$toolbar_item_translation']"); } /** @@ -62,11 +64,19 @@ public function provider(): array { return [ 'Language code both in Drupal and CKEditor' => [ 'langcode' => 'th', - 'blockquote_translation' => 'คำพูดบล็à¸à¸', + 'toolbar_item_name' => 'blockQuote', + 'toolbar_item_translation' => 'คำพูดบล็à¸à¸', ], 'Language code transformed from browser mappings' => [ 'langcode' => 'zh-hans', - 'blockquote_translation' => 'å—引用', + 'toolbar_item_name' => 'blockQuote', + 'toolbar_item_translation' => 'å—引用', + ], + 'Language configuration conflict' => [ + 'langcode' => 'fr', + 'toolbar_item_name' => 'textPartLanguage', + // cSpell:disable-next-line + 'toolbar_item_translation' => 'Choisir la langue', ], ]; }