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.
Issue fork ai_image_alt_text-3532068
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
anybodyI think this can be seen as bug for multilang projects