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 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'
  ];

  export default function WProofreaderSync(editor) {
    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

#to_h

Methods inherited from Editor::PropsBasePlugin

normalize, #preload_assets_bundle, #to_h

Constructor Details

#initializeWProofreaderSync

Returns a new instance of WProofreaderSync.



61
62
63
# File 'lib/ckeditor5/rails/plugins/wproofreader.rb', line 61

def initialize
  super(:WProofreaderSync, PLUGIN_CODE)
end