Multilanguage support at file upload

Created on 24 June 2025, 20 days ago

Problem/Motivation

The text language is determined in ai_image_alt_text.module hook_field_widget_single_element_form_alter(). When editing an existing media, the langcode is fetched from the form object's entity (MediaForm).
When uploading an image, there is no getEntity method in the form object (FileUploadForm) --- therefore the site's default language is assigned (which normally is 'en').
With a multilanguage site, e.g. on a node with langcode 'de' (german), the text is generated in the default language, which (in my case) is english.

It would be very nice to have the correct language also for file uploads.

Proposed resolution

If the method getEntity() doesn't exist, try to get the parent entity from the request and fetch its langcode instead of the default language.

Feature request
Status

Active

Version

1.0

Component

Code

Created by

🇩🇪Germany drupatz

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024