Class: CKEditor5::Rails::Plugins::WProofreaderSync

Inherits:
Editor::PropsInlinePlugin show all
Defined in:
lib/ckeditor5/rails/plugins/wproofreader.rb

Overview

Sync I18n language from editor to WProofreader plugin

Constant Summary collapse

PLUGIN_CODE =
<<~JS
  const { Plugin, FileRepository } = await import( 'ckeditor5' );
  const CORRECTION_LANGUAGES = [
    'en_US', 'en_GB', 'pt_BR', 'da_DK',
    'nl_NL', 'en_CA', 'fi_FI', 'fr_FR',
    'fr_CA', 'de_DE', 'el_GR', 'it_IT',
    'nb_NO', 'pt_PT', 'es_ES', 'sv_SE',
    'uk_UA', 'auto'
  ];

  return class WproofreaderSync extends Plugin {
    static get pluginName() {
      return 'WProofreaderSync';
    }

    async init() {
      const { editor } = this;

      const wproofreaderConfig = editor.config.get('wproofreader');
      const editorLangCode = (() => {
        const config = editor.config.get('language');

        return config.content || config.ui;
      })();

      if (!wproofreaderConfig || !editorLangCode) {
        return;
      }

      const lang = CORRECTION_LANGUAGES.find(
        lang => lang.startsWith(editorLangCode.toLowerCase())
      ) || 'auto';

      editor.config.set('wproofreader', {
        lang,
        localization: editorLangCode,
        ...wproofreaderConfig,
      });
    }
  }
JS

Instance Attribute Summary

Attributes inherited from Editor::PropsInlinePlugin

#code

Attributes inherited from Editor::PropsBasePlugin

#assets_bundle, #name

Instance Method Summary collapse

Methods inherited from Editor::PropsInlinePlugin

#compress!, #to_h

Methods inherited from Editor::PropsBasePlugin

normalize, #preload_assets_bundle, #to_h

Constructor Details

#initializeWProofreaderSync

Returns a new instance of WProofreaderSync.



70
71
72
73
# File 'lib/ckeditor5/rails/plugins/wproofreader.rb', line 70

def initialize
  super(:WProofreaderSync, PLUGIN_CODE)
  compress!
end