- Issue created by @drupatz
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.
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.
Active
1.0
Code