Hat tip to @jhodgdon for finding this.

Problem/Motivation

The Editor config entity cannot be translated because it does not have a dedicated edit form. Instead the editor settings are attached to the edit form of the TextFormat config entity.

Because editor settings do not have any translatable settings in core this is marked minor and also not tagged with sprint. However, because editor settings support third_party_settings contrib modules could add translatable values there and expect to be able to translate them with the Config Translation module. A use-case would be being able to edit button labels (or alt tags, or title tags).

Proposed resolution

Add the appropriate editor config object to the text format's config translation mapper.

Remaining tasks

User interface changes

None.

API changes

None.

Data model changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tstoeckler created an issue. See original summary.

Wim Leers’s picture

Assigned: Unassigned » Gábor Hojtsy

I'm not quite sure what Add the appropriate editor config object to the text format's config translation mapper. means.

Also, there actually are translatable things even without third-party settings:

  1. Go to /admin/config/content/formats/manage/basic_html
  2. Drag the Styles dropdown from Available buttons to somewhere in Active toolbar
  3. Now a Styles dropdown vertical tab appears under CKEditor plugin settings. Enter something like blockquote.famous|Famous quote

Now Famous quote is a config value that you actually want to translate.

Assigning to @Gábor Hojtsy for feedback.

Gábor Hojtsy’s picture

#2546212: Entity view/form mode formatter/widget settings have no translation UI is a similar problem. Basically translation mappers in config translation map a set of config names to a route. So it can add a translate tab and several other routes to allow looking at translation status, translating the configs and deleting translations. So I think editor configs are edited on text format config pages, so you would need to alter the mapper for text formats to also have the editor entity. Again all the things that #2546212: Entity view/form mode formatter/widget settings have no translation UI is postponed on would help as well as the implementation proposed for #2546212: Entity view/form mode formatter/widget settings have no translation UI overall.

Gábor Hojtsy’s picture

Assigned: Gábor Hojtsy » Unassigned
tstoeckler’s picture

Title: Editor settings cannot be translated » [PP-1] Editor settings cannot be translated
Priority: Minor » Normal

Ahem, that makes this definitely not Minor. Not sure if it should be Major even, I'll let others decide that. Thanks for the info!

What I meant was the following:
The Configuration Translation module works in a way that can point it to a route and tell it what config objects to translate and then it adds new routes that live under /translate for the translation UI. We call these things "config mappers".

Benefitting from the generic integration we have for config entities, you can already translate text formats at e.g. /admin/config/content/formats/manage/basic_html/translate. Thus a config mapper already exists for text formats. Because Text Editor module enhances the text format UI and adds corresponding config objects, so it should also enhance the text format translation UI to add the respective editor.editor.* config object to the text format mapper.

Writing this, I realize this in fact needs #2577761: We need a way to dynamically alter the list of config names for config mappers in order to work. Once that is in, editor module could add an event subscriber which listens to the ConfigTranslation::POPULATE_MAPPER event and then does something like:

if (($mapper instanceof ConfigEntityMapper) && ($mapper->getId() === 'text_format')) {
  $text_format_id = $mapper->getEntity()->id();
  if ($editor = $this->editorStorage->load($text_format_id) {
    $mapper->addConfigName($editor->getConfigDependencyName());
  }
}

(or similar)

EDIT: Massive x-post!

tstoeckler’s picture

Wim Leers’s picture

Version: 8.0.x-dev » 8.1.x-dev
Status: Active » Postponed

Updating status to reflect reality. Blocked on #2577761: We need a way to dynamically alter the list of config names for config mappers, hence marking as postponed. And since #2577761 was moved to 8.1, also moving this issue to 8.1.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

tacituseu’s picture

Title: [PP-1] Editor settings cannot be translated » Editor settings cannot be translated
Status: Postponed » Active
Wim Leers’s picture

So this now just needs to do something like \Drupal\config_translation_test\EventSubscriber\ConfigTranslationTestSubscriber, or #2546212-90: Entity view/form mode formatter/widget settings have no translation UI. Let's do it!

Gábor Hojtsy’s picture

Yay, finally possible to fix :)

Wim Leers’s picture

@Gábor Hojtsy: Is that a response to #15 or did something else happen recently? :)

Gábor Hojtsy’s picture

Nothing recently other than some activity in #2546212: Entity view/form mode formatter/widget settings have no translation UI that prompted me to look here as well.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Berdir’s picture

Status: Active » Needs review
Issue tags: +Needs tests
FileSize
2.57 KB

In spirit of https://twitter.com/berdir/status/1113529017410387970, adding one more patch to our project :)

This is very much a proof of concept, I didn't do a lot of testing and, and as the example of the stylescombo config shows, it will most likely need more config changes.

Also, as always, integrating two modules that don't depend on each other is tricky, especially with events, add a class_exists() check as workaround for that now, we really should have module dependencies on services...

Berdir’s picture

FileSize
42.65 KB

forgot the proof that it works:

tstoeckler’s picture

+++ b/core/modules/editor/src/EventSubscriber/EditorConfigTranslationSubscriber.php
@@ -0,0 +1,40 @@
+    if ($mapper instanceof ConfigEntityMapper && $mapper->getType() == 'filter_format' && $mapper->getLangcode() === 'en') {

Why is the langcode check needed? I wouldn't have thought that to be the case.

Berdir’s picture

Absolutely no clue, the test does that? :)

ytsurk’s picture

Yes. I got it only working with the langcode check removed.

The mapper's language was NULL in my case, where the standard config language is German.

ytsurk’s picture

Status: Needs review » Needs work

Alright, this now throws an error if the config file (editor.editor.[format_name]) does not exist yet, thus has not editor:

Drupal\config_translation\Exception\ConfigMapperLanguageException: A config mapper can only contain configuration for a single language. in Drupal\config_translation\ConfigNamesMapper->getLangcode() (line 405 of core/modules/config_translation/src/ConfigNamesMapper.php)

Again in a setup where German is the default config language.

Caused by ConfigNamesMapper's:

  public function getLangcodeFromConfig($config_name) {
    // Default to English if no language code was provided in the file.
    // Although it is a best practice to include a language code, if the
    // developer did not think about a multilingual use case, we fall back
    // on assuming the file is English.
    return $this->configFactory->get($config_name)->get('langcode') ?: 'en';
  }

So we need to skip filter formats not having a WYSIWYG editor.

ytsurk’s picture

Here a new patch checking if the filter format has an editor set.

ytsurk’s picture

Status: Needs work » Needs review
tstoeckler’s picture

Status: Needs review » Needs work

Thanks for your work @ytsurk!

So if I understand you correctly the latest patches fixes the issue you were seeing in regards to different languages? If so, great! The patch looks good and makes a lot of sense. Now we just need a test for it. Marking "needs work" for that.

Also I see two possible follow-ups:

  1. Remove the langcode check from ConfigTranslationTestSubscriber
  2. Add a more explicit exception if a config name of a non-existant config is added to a mapper
ytsurk’s picture

  1. The removal of the langcode check made it work on a site with German as default language for configs.
  2. The check if a editor exists made it work for filter formats without editor
Berdir’s picture

Reroll after #3063020: Support translation of the list of styles in CKEditor which tried to fix this too but that's not enough.

I'm adding a basic translation test,

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Wim Leers’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll, +Novice
  1. +++ b/core/modules/ckeditor/tests/src/Functional/CKEditorStylesComboTranslationTest.php
    @@ -0,0 +1,82 @@
    +  /**
    +   * Modules to enable.
    +   *
    +   * @var array
    +   */
    

    🤓 {inheritdoc}

  2. +++ b/core/modules/ckeditor/tests/src/Functional/CKEditorStylesComboTranslationTest.php
    @@ -0,0 +1,82 @@
    +   * A random generated format machine name.
    

    🤓 s/random/randomly/

  3. +++ b/core/modules/ckeditor/tests/src/Functional/CKEditorStylesComboTranslationTest.php
    @@ -0,0 +1,82 @@
    +   * Tests translations of ckeditor styles configuration.
    

    🤓 s/ckeditor/CKEditor/

  4. +++ b/core/modules/editor/src/EventSubscriber/EditorConfigTranslationSubscriber.php
    @@ -0,0 +1,63 @@
    +use function class_exists;
    

    🤯

  5. +++ b/core/modules/editor/src/EventSubscriber/EditorConfigTranslationSubscriber.php
    @@ -0,0 +1,63 @@
    +class EditorConfigTranslationSubscriber implements EventSubscriberInterface {
    +
    +
    +  /**
    

    Übernit: excess whitespace.

  6. +++ b/core/modules/editor/src/EventSubscriber/EditorConfigTranslationSubscriber.php
    @@ -0,0 +1,63 @@
    +  public function __construct($config_factory) {
    

    Shoudln't this be typehinted?

  7. +++ b/core/modules/editor/src/EventSubscriber/EditorConfigTranslationSubscriber.php
    @@ -0,0 +1,63 @@
    +      // Only add the editor config if it exists, otherwise we assume no editor
    +      // has been set for this filter format.
    

    Nits:
    - s/editor/text editor/
    - s/filter format/text format/

shubham.prakash’s picture

Patch added for issues mentioned in #33.

Status: Needs review » Needs work

The last submitted patch, 34: 2571371-34.patch, failed testing. View results

shubham.prakash’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
5.77 KB
Wim Leers’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Thanks, @shubham.prakash! 👍 Could you please provide an interdiff in the future? That makes reviews much easier! 🙂

Manually compared. Looks good! Two remaining remarks:

  1. #33.6 has not yet been addressed.
  2. +++ b/core/modules/editor/src/EventSubscriber/EditorConfigTranslationSubscriber.php
    @@ -0,0 +1,61 @@
    +      // Only add the text editor config if it exists, otherwise we assume no editor
    +      // has been set for this text format.
    

    🤓 This line now is longer than 80 cols. The last word needs to be moved to the next line.

shubham.prakash’s picture

Status: Needs work » Needs review
FileSize
5.77 KB
1.14 KB

Thanks for the review, I would make sure to provide interdiff now.

I am not sure about the type hinting as why it gave failed test cases in #34.
The commented line has been wrapped as said.

Wim Leers’s picture

Status: Needs review » Needs work

Aha, I missed that!

You forgot the use statement, and that's why it failed the way it did. Typehinting + importing the correct interface through a use statement should work fine 🙂

Once that's done, this is ready!

shubham.prakash’s picture

Status: Needs work » Needs review
FileSize
5.84 KB
1.27 KB

Hope this resolves the issue.

Status: Needs review » Needs work

The last submitted patch, 40: 2571371-40.patch, failed testing. View results

Wim Leers’s picture

It did! :)

The remaining failure is now due to the newly added requirement that you specify a $defaultTheme property on your test class.

shubham.prakash’s picture

Status: Needs work » Needs review
FileSize
5.92 KB
901 bytes
aleevas’s picture

Issue tags: -Needs reroll
Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

Perfect, thank you!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed f68812c39a to 9.0.x and 9c054814f3 to 8.9.x. Thanks!

alexpott’s picture

Version: 8.9.x-dev » 8.8.x-dev
Status: Fixed » Patch (to be ported)

Asked the other committers about backporting this to 8.8.x

  • alexpott committed f68812c on 9.0.x
    Issue #2571371 by shubham.prakash, Berdir, ytsurk, Wim Leers, tstoeckler...

  • alexpott committed 9c05481 on 8.9.x
    Issue #2571371 by shubham.prakash, Berdir, ytsurk, Wim Leers, tstoeckler...
alexpott’s picture

Status: Patch (to be ported) » Fixed

Discussed with @catch who +1'd the backport.

  • alexpott committed ce03247 on 8.8.x
    Issue #2571371 by shubham.prakash, Berdir, ytsurk, Wim Leers, tstoeckler...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.