.../lib/Drupal/ckeditor/Plugin/Editor/CKEditor.php | 5 ++ core/modules/locale/locale.module | 61 +++++++++++++------- 2 files changed, 44 insertions(+), 22 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 94fa1ac..5b37086 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/Editor/CKEditor.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/Editor/CKEditor.php @@ -259,6 +259,11 @@ public function getJSSettings(EditorEntity $editor) { 'drupalExternalPlugins' => array_map('file_create_url', $external_plugin_files), ); + // Parse all CKEditor plugin JavaScript files for translations. + if ($this->moduleHandler->moduleExists('locale')) { + locale_js_translate(array_values($settings['drupalExternalPlugins'])); + } + ksort($settings); return $settings; diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 9819f18..b37af1f 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -585,31 +585,47 @@ function locale_system_remove($components) { /** * Implements hook_js_alter(). - * - * This function checks all JavaScript files currently added via drupal_add_js() - * and invokes parsing if they have not yet been parsed for Drupal.t() - * and Drupal.formatPlural() calls. Also refreshes the JavaScript translation - * file if necessary, and adds it to the page. */ function locale_js_alter(&$javascript) { + $files = array(); + foreach ($javascript as $item) { + if (isset($item['type']) && $item['type'] == 'file') { + $files[] = $item['data']; + } + } + if ($translation_file = locale_js_translate($files)) { + $javascript[$translation_file] = drupal_js_defaults($translation_file); + } +} +/** + * Returns a list of translation files given a list of JavaScript files. + * + * This function checks all JavaScript files passed and invokes parsing if they + * have not yet been parsed for Drupal.t() and Drupal.formatPlural() calls. + * Also refreshes the JavaScript translation files if necessary, and returns + * the filepath to the translation file (if any). + * + * @param array $files + * An array of local file paths. + * @return string|NULL + * The filepath to the translation file or NULL if no translation is + * applicable. + */ +function locale_js_translate(array $files = array()) { $language_interface = language(Language::TYPE_INTERFACE); - $dir = 'public://' . Drupal::config('local.settings')->get('javascript.directory'); + $dir = 'public://' . Drupal::config('locale.settings')->get('javascript.directory'); $parsed = Drupal::state()->get('system.javascript_parsed') ?: array(); - $files = $new_files = FALSE; - - foreach ($javascript as $item) { - if (isset($item['type']) && $item['type'] == 'file') { - $files = TRUE; - $filepath = $item['data']; - if (!in_array($filepath, $parsed)) { - // Don't parse our own translations files. - if (substr($filepath, 0, strlen($dir)) != $dir) { - _locale_parse_js_file($filepath); - $parsed[] = $filepath; - $new_files = TRUE; - } + $new_files = FALSE; + + foreach ($files as $filepath) { + if (!in_array($filepath, $parsed)) { + // Don't parse our own translations files. + if (substr($filepath, 0, strlen($dir)) != $dir) { + _locale_parse_js_file($filepath); + $parsed[] = $filepath; + $new_files = TRUE; } } } @@ -639,11 +655,12 @@ function locale_js_alter(&$javascript) { // Add the translation JavaScript file to the page. $locale_javascripts = Drupal::state()->get('translation.javascript') ?: array(); - if ($files && !empty($locale_javascripts[$language_interface->id])) { + $translation_file = NULL; + if (!empty($files) && !empty($locale_javascripts[$language_interface->id])) { // Add the translation JavaScript file to the page. - $file = $dir . '/' . $language_interface->id . '_' . $locale_javascripts[$language_interface->id] . '.js'; - $javascript[$file] = drupal_js_defaults($file); + $translation_file = $dir . '/' . $language_interface->id . '_' . $locale_javascripts[$language_interface->id] . '.js'; } + return $translation_file; } /**