.../lib/Drupal/ckeditor/Plugin/Editor/CKEditor.php | 22 ++++++++++++-------- core/modules/language/config/language.mappings.yml | 3 +++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/Editor/CKEditor.php b/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/Editor/CKEditor.php index 335003b..931a45e 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/Editor/CKEditor.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/Editor/CKEditor.php @@ -229,14 +229,14 @@ public function getJSSettings(EditorEntity $editor) { $settings += $plugin->getConfig($editor); } - // Fallback on English if no matching language code was found. + // Fall back on English if no matching language code was found. $display_langcode = 'en'; - // Match the interface language code with possible pairs from ckeditor. + // Map the interface language code to a CKEditor translation. $ckeditor_langcodes = $this->getLangcodes(); $language_interface = $this->languageManager->getLanguage(Language::TYPE_INTERFACE); if (isset($ckeditor_langcodes[$language_interface->id])) { - $display_langcode = $language_interface->id; + $display_langcode = $ckeditor_langcodes[$language_interface->id]; } // Next, set the most fundamental CKEditor settings. @@ -284,22 +284,26 @@ private function getLangcodes() { // Collect languages included with CKEditor based on file listing. $ckeditor_languages = glob(DRUPAL_ROOT . '/core/assets/vendor/ckeditor/lang/*.js'); foreach ($ckeditor_languages as $language_filename) { - $langcode = basename($language_filename); + $langcode = basename($language_filename, '.js'); $langcodes[$langcode] = $langcode; } cache('ckeditor')->set('langcodes', $langcodes); } // Get language mapping if available to map to Drupal language codes. - // This is configurable on the user interface and not expensive to get, - // so we don't include in the cached language list. + // This is configurable in the user interface and not expensive to get, so + // we don't include it in the cached language list. $language_mappings = $this->moduleHandler->moduleExists('language') ? language_get_browser_drupal_langcode_mappings() : array(); foreach ($langcodes as $langcode) { - // If this language code is available in a Drupal mapping, use that - // to compute a possibility for matching from the Drupal langcode to - // the CKEditor langcode. + // If this language code is available in a Drupal mapping, use that to + // compute a possibility for matching from the Drupal langcode to the + // CKEditor langcode. + // e.g. CKEditor uses the langcode 'no' for Norwegian, Drupal uses 'nb'. + // This would then remove the 'no' => 'no' mapping and replace it with + // 'nb' => 'no'. Now Drupal knows which CKEditor translation to load. if (isset($language_mappings[$langcode]) && !isset($langcodes[$language_mappings[$langcode]])) { $langcodes[$language_mappings[$langcode]] = $langcode; + unset($langcodes[$langcode]); } } diff --git a/core/modules/language/config/language.mappings.yml b/core/modules/language/config/language.mappings.yml index e4ef2a1..ede8c9e 100644 --- a/core/modules/language/config/language.mappings.yml +++ b/core/modules/language/config/language.mappings.yml @@ -1,5 +1,8 @@ # Browsers use different language codes to refer to the same languages, # these defaults handles the most common cases. +no: 'nb' # Norwegian +pt-pt: 'pt' # Portuguese +zh: 'zh-hans' zh-tw: 'zh-hant' # Taiwan Chinese in traditional script zh-hk: 'zh-hant' # Hong Kong Chinese in traditional script zh-mo: 'zh-hant' # Macao Chinese in traditional script