1 ckeditor5.module ckeditor5_js_alter(&$javascript)

Implements hook_js_alter().

Adds a matching CKEditor 5 translation file if the UI is non-English.

File

core/modules/ckeditor5/ckeditor5.module, line 224
Provides integration with the CKEditor WYSIWYG editor.

Code

function ckeditor5_js_alter(&$javascript) {
  global $language;
  if ($language->langcode === 'en') {
    return;
  }

  $module_path = backdrop_get_path('module', 'ckeditor5');
  $build_path = $module_path . '/lib/ckeditor5/build';
  $js_path = $build_path . '/ckeditor5-dll.js';
  $translation_path = $build_path . '/translations/' . $language->langcode . '.js';

  // If the ckeditor5-dll.js library is present AND a translation file exists
  // for the current language, append the translation file to the JavaScript
  // array.
  if (isset($javascript[$js_path]) && file_exists($translation_path)) {
    // Copy the CKEditor library settings, which will be nearly identical the
    // translation settings (same preprocessing, scope, weight, version, etc.)
    $javascript[$translation_path] = $javascript[$js_path];
    $javascript[$translation_path]['data'] = $translation_path;
  }
}