Problem/Motivation

Allow a data-langcode attribute on drupal-media to set the translation. Right now, it always inherits from the host entity's language.

Proposed resolution

In MediaEmbed::process() add something like this:

      // Allow data-langcode to override the translation.
      if ($node->hasAttribute('data-langcode')) {
        $langcode = $node->getAttribute('data-langcode');
      }

Remaining tasks

TBD

User interface changes

TBD

API changes

TBD

Data model changes

TBD

Release notes snippet

Comments

oknate created an issue. See original summary.

oknate’s picture

Issue summary: View changes
Issue tags: +Needs tests
StatusFileSize
new860 bytes

Here's an initial patch that worked for me when testing manually. Adding "Needs tests" tag. I'll work on test coverage for this when I get a chance.

oknate’s picture

Status: Active » Needs review
Issue tags: -Needs tests
StatusFileSize
new3.55 KB
new2.71 KB

Adding test coverage.

oknate’s picture

StatusFileSize
new734 bytes
new3.18 KB

Removing a line I added that was no longer needed. Originally I was going to test with another language.

wim leers’s picture

I intentionally did not port data-langcode from https://www.drupal.org/project/entity_embed to core's MediaEmbed filter in #2940029: Add an input filter to display embedded Media entities, because it's

  1. extra complexity (in code, but especially for the content author)
  2. something that the user would only be able to set in … the dialog that #2994702: Allow editors to alter embed-specific metadata, as well as `data-align` and `data-caption` is adding
  3. far less useful for media embeds than arbitrary entity embeds. I'd argue that 99% of the time the media that you embed must match the language of the host entity, even if only for the sake of alt text on image media or the fallback text for HTML5 video media or the title of document media.
  4. also got HTML impact/requirements for correct semantics and accessibility. We'd also need to set the lang attribute for WCAG 3.1.2 Language of Parts compliance. Just like the https://ckeditor.com/cke4/addon/language plugin lets you do for arbitrary text, which was added to Drupal 8.1 in #1993928: Language of parts: Introduce a language toolbar button. Arguably this should be integrated with that instead: that should let you choose the language of the embedded media, and not the dialog in #2940029: Add an input filter to display embedded Media entities
gábor hojtsy’s picture

I agree that this would be extra complexity that is probably not needed for the 80% use case. There may be edge cases when someone wants to embed media of another language in an entity but that sounds highly atypical unless I am missing something.

If for some reason we should really have this on the api then we could add support for the attribute (and tests) but not expose it on the UI. Then an advanced use case can alter the form to support it but it would be crowd the form by default.

wim leers’s picture

Status: Needs review » Postponed

Great.

FWIW: as soon as there is interest in this functionality by at least 10 people, I'd be happy to write a contributed module for this.

For now, marking this as a postponed feature request, because we have consensus this is not widely used enough to justify adding the additional code and maintenance work to Drupal core.

wim leers’s picture

Status: Postponed » Closed (works as designed)

Actually, we usually mark this Closed (works as designed). Doing that here too.