Issue #2318237 by Gábor Hojtsy, bserem, no_angel, Wim Leers: CKEditor translates its user interface even if interface translation is turned off
parent
a92c3a110a
commit
bb03d397cc
|
|
@ -258,11 +258,14 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
|
|||
// Fall back on English if no matching language code was found.
|
||||
$display_langcode = 'en';
|
||||
|
||||
// Map the interface language code to a CKEditor translation.
|
||||
$ckeditor_langcodes = $this->getLangcodes();
|
||||
$language_interface = $this->languageManager->getCurrentLanguage();
|
||||
if (isset($ckeditor_langcodes[$language_interface->getId()])) {
|
||||
$display_langcode = $ckeditor_langcodes[$language_interface->getId()];
|
||||
// Map the interface language code to a CKEditor translation if interface
|
||||
// translation is enabled.
|
||||
if ($this->moduleHandler->moduleExists('locale')) {
|
||||
$ckeditor_langcodes = $this->getLangcodes();
|
||||
$language_interface = $this->languageManager->getCurrentLanguage();
|
||||
if (isset($ckeditor_langcodes[$language_interface->getId()])) {
|
||||
$display_langcode = $ckeditor_langcodes[$language_interface->getId()];
|
||||
}
|
||||
}
|
||||
|
||||
// Next, set the most fundamental CKEditor settings.
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@
|
|||
namespace Drupal\ckeditor\Tests;
|
||||
|
||||
use Drupal\simpletest\KernelTestBase;
|
||||
use Drupal\editor\Plugin\EditorManager;
|
||||
use Drupal\ckeditor\Plugin\Editor\CKEditor;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\editor\Entity\Editor;
|
||||
|
||||
/**
|
||||
* Tests for the 'CKEditor' text editor plugin.
|
||||
|
|
@ -368,6 +368,10 @@ class CKEditorTest extends KernelTestBase {
|
|||
// Language codes only in CKEditor.
|
||||
$this->assertTrue($langcodes['en-au'] == 'en-au', '"en-au" properly resolved');
|
||||
$this->assertTrue($langcodes['sr-latn'] == 'sr-latn', '"sr-latn" properly resolved');
|
||||
|
||||
// No locale module, so even though languages are enabled, CKEditor should
|
||||
// still be in English.
|
||||
$this->assertCKEditorLanguage('en');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -377,11 +381,38 @@ class CKEditorTest extends KernelTestBase {
|
|||
$this->enableModules(array('language', 'locale'));
|
||||
$this->installSchema('locale', 'locales_source');
|
||||
$this->installSchema('locale', 'locales_location');
|
||||
$editor = entity_load('editor', 'filtered_html');
|
||||
$this->installSchema('locale', 'locales_target');
|
||||
$editor = Editor::load('filtered_html');
|
||||
$this->ckeditor->getJSSettings($editor);
|
||||
$localeStorage = $this->container->get('locale.storage');
|
||||
$string = $localeStorage->findString(array('source' => 'Edit Link', 'context' => ''));
|
||||
$this->assertTrue(!empty($string), 'String from JavaScript file saved.');
|
||||
|
||||
// With locale module, CKEditor should not adhere to the language selected.
|
||||
$this->assertCKEditorLanguage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that CKEditor picks the expected language when French is default.
|
||||
*
|
||||
* @param string $langcode
|
||||
* Language code to assert for. Defaults to French. That is the default
|
||||
* language set in this assertion.
|
||||
*/
|
||||
protected function assertCKEditorLanguage($langcode = 'fr') {
|
||||
// Set French as the site default language.
|
||||
ConfigurableLanguage::createFromLangcode('fr')->save();
|
||||
\Drupal::config('system.site')->set('langcode', 'fr')->save();
|
||||
|
||||
// Reset the language manager so new negotiations attempts will fall back on
|
||||
// French. Reinject the language manager CKEditor to use the current one.
|
||||
$this->container->get('language_manager')->reset();
|
||||
$this->ckeditor = $this->container->get('plugin.manager.editor')->createInstance('ckeditor');
|
||||
|
||||
// Test that we now get the expected language.
|
||||
$editor = Editor::load('filtered_html');
|
||||
$settings = $this->ckeditor->getJSSettings($editor);
|
||||
$this->assertEqual($settings['language'], $langcode);
|
||||
}
|
||||
|
||||
protected function getDefaultInternalConfig() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue