Add option to select from Drupal's enabled languages to CKEditor "Language" button

Created on 27 August 2023, about 1 year ago

Problem/Motivation

CKEditor's Language button permits a content editor to apply lang attribute to content sections.

While Drupal can be configured to use multiple languages, including custom languages, this CKEditor interface only permits picking one of two lists of languages, neither supporting custom languages.

  1. United Nations' official languages
  2. "All" languages (the label says "all", but it's not all languages, it's the predefined list from LanguageManager::getStandardLanguageList()

In our use case we only need 2 languages for a bilingual site. We cannot use the UN list or the standard list as Māori does not appear in either. Even if all the desired languages do appear in the full list, the content editor UX would be improved for many sites by reducing the number of unused languages from the list to choose from.

This was previously raised against Drupal core in Third option for the CKEditor 4 "Language" button: `enabled` (in addition to `un` and `all`) Needs review and moved to CKEditor 4 when that module went to contrib. It is also raised in #1993928-216: Language of parts: Introduce a language toolbar button .

Steps to reproduce

  1. Install Drupal and enable Content translation, Language and any required modules, along with CKEditor
  2. At /admin/config/regional/language, press "Add a language"
  3. Select "Custom language" and enter "mi" for language code and "Māori" for title
  4. At /admin/config/content/formats/manage/basic_html under "CKEditor 5 plugin settings - Source editing", add <span lang dir> to the allowed tags and press Save
  5. At /admin/config/content/formats/manage/basic_html under "Toolbar configuration", drag the "Language" button to the CKEditor toolbar
  6. At /admin/config/content/formats/manage/basic_html under "CKEditor 5 plugin settings - Language", the options are "United Nations official languages" and "All 107 languages". Choose "All 107 languages" (results are same regardless)
  7. Create some content using the configured input format, and note that the custom language configured in (3) above is not available
  8. Note that even with two languages enabled for the site, the UX of finding a language in a list of 107 languages is poor

Proposed resolution

Add a third option to "Language" CKEditor plugin configuration form: Enabled, which presents the currently enabled languages for the site.

Remaining tasks

  1. agree on approach
  2. implement
  3. code
  4. review
  5. test
  6. commit

User interface changes

TBC

API changes

CKEditor 5 "Language" plugin will need access to the language manager service.

Data model changes

None

Release notes snippet

TBD

🐛 Bug report
Status

Closed: duplicate

Version

11.0 🔥

Component

ckeditor.module

Created by

🇳🇿New Zealand xurizaemon Ōtepoti, Aotearoa 🏝

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024