Score:1

How do I override /libraries/ckeditor-wordcount-plugin/lang/some.js?

de flag

I'm using ckwordcount module which basically adds nice max length and counter features to text Fields, and relies on WordCount Plugin for CKEditor Editor.

Most of the translations in the plugin lang directory are incomplete, resulting in messy undefined strings displayed where we'd expect a clear message for end users...

Just to make sure this was the plugin translation source I edited the original file in /libraries/ckeditor-wordcount-plugin/wordcount/lang/ folder and it works, but for obvious reasons I can't do this way.

So I tried to override that file in many ways, without success. First in my admin subtheme, I added a js file to declare more CKEditor config variables. The inner part of declaration (CKEDITOR.plugins.setLang) is a copy of the original, so I'm sure this is the right syntax :

admin_subtheme/js/customCkeditorConfig.js

(function ($, Drupal) {
  Drupal.behaviors.CKEditorConfig = {
    attach: function (context, settings) {
      if (typeof CKEDITOR !== "undefined") {
        CKEDITOR.plugins.setLang('wordcount', 'fr', {
          WordCount: 'Mots :',
          WordCountRemaining: 'Mots restants',
          CharCount: 'Caractères :',
          CharCountWithHTML: 'Caractères (incluant HTML) :',
          CharCountWithHTMLRemaining: 'caractère(s) restant(s), incluant les sauts de lignes, espaces ...',
          Paragraphs: 'Paragraphes :',
          ParagraphsRemaining: 'Paragraphes restants',
          pasteWarning: 'Le contenu ne peut pas être collé car il dépasse la limite autorisée',
          Selected: 'Sélectionné :',
          title: 'Statistiques'
        });
      }
    }
  }
})(jQuery, Drupal);

After clearing caches the file is called but not applied. I guess it might be overridden by the original one that is loaded after ?

I also tried to use the libraries-override syntax in the info.yml file. I could not find any doc that explain how to proceed with external libraries, so I tried whatever I could imagine !

admin_subtheme.info.yml

libraries-override:
  system/base:
    js:
      /libraries/ckeditor-wordcount-plugin/wordcount/lang/fr.js: js/ckeditor-wordcount-plugin/fr.js

  libraries/ckeditor-wordcount-plugin:
    js:
      wordcount/lang/fr.js: js/ckeditor-wordcount-plugin/fr.js

  core/ckeditor-wordcount-plugin:
    js:
      wordcount/lang/fr.js: js/ckeditor-wordcount-plugin/fr.js

  w8tcha/ckeditor-wordcount-plugin:
    js:
      wordcount/lang/fr.js: js/ckeditor-wordcount-plugin/fr.js

  global:
    js:
      /libraries/ckeditor-wordcount-plugin/wordcount/lang/fr.js: js/ckeditor-wordcount-plugin/fr.js

Any idea, please ? Thanks a lot.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.