Repository: WeblateOrg/weblate

Issue:
Unable to translate a project component using another project component
### Describe the issue

Hello,

I would translate a `Project A/Component 1` using a `Project B/Component 2`
Unfortunately, if I'm going into Tools > Automatic Translations from `Project A/Component 1`, the field `Component` from the form when `Other translations components` is checked is empty.

I tried to fill the input field using either `project/component` syntax or `digit` where "digit" is the component ID (picked from the components table) - in both case, Weblate is returning an error and the mechanics does nothing :(

Component are using XLIFF format.

### I already tried

- [X] I've read and searched [the documentation](https://docs.weblate.org/).
- [X] I've searched for similar issues in this repository.

### Steps to reproduce the behavior

1. Go to `Projects`
2. Select `Project A`
3. Click on `Component 1`
4. Use `French(fr-FR)` language
5. Click on `Tools` followed by `Automatic Translations`
6. Fill the form as bellow
    - `Translations mode` using `Add translations`
    - `Search criteria` use `Untranslated strings`
    - `Source` with `Other component` checked
    - `Component` filled with either
        a. `Project B/Component 2`
        b. `Project B/Component 2` numeric ID

### Expected behavior

At best, I would get access to available Project/Component list in the input form
At least, I the automatic translation is working with other project/component like it used to :)

### Screenshots

![image](https://github.com/WeblateOrg/weblate/assets/648753/17a8bd12-8971-4faf-976b-6266bf4117a5)

![image](https://github.com/WeblateOrg/weblate/assets/648753/d7cfd648-6536-4842-b40a-9f0d13458ced)

![image](https://github.com/WeblateOrg/weblate/assets/648753/755b85a2-5628-4ec3-9989-438eafda4fe2)

### Exception traceback

```
weblate-docker-weblate-1  | nginx stdout | 176.157.202.49 - - [24/Nov/2023:11:09:31 +0100] "POST /auto-translate/4ps/4ps-construct-fr-22-2/fr-FR/ HTTP/1.1" 302 5 "https://weblate.talent-bs.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0"
```

**EDIT:** might be related, while attempting to do the same action using console, I get the stack bellow

```
sudo docker compose exec --user weblate weblate weblate auto_translate project-a component-1 fr-FR --source project-b/component-2
```

```pytb
Traceback (most recent call last):
  File "/usr/local/bin/weblate", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/lib/python3.11/site-packages/weblate/runner.py", line 19, in main
    utility.execute()
  File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.11/site-packages/django/core/management/base.py", line 412, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.11/site-packages/weblate/utils/management/base.py", line 27, in execute
    return super().execute(*args, **options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/core/management/base.py", line 458, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/weblate/trans/management/commands/auto_translate.py", line 98, in handle
    result = auto_translate(
             ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/celery/local.py", line 182, in __call__
    return self._get_current_object()(*a, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/celery/app/task.py", line 411, in __call__
    return self.run(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/celery/app/autoretry.py", line 38, in run
    return task._orig_run(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/weblate/trans/tasks.py", line 419, in auto_translate
    auto.process_others(component)
  File "/usr/local/lib/python3.11/contextlib.py", line 81, in inner
    return func(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/weblate/trans/autotranslate.py", line 105, in process_others
    raise PermissionDenied("Component have different source languages.")
django.core.exceptions.PermissionDenied: Component have different source languages.
```


### How do you run Weblate?

Docker container

### Weblate versions

```
 * Weblate: 5.2
 * Django: 4.2.7
 * siphashc: 2.3
 * translate-toolkit: 3.11.1
 * lxml: 4.9.3
 * Pillow: 10.1.0
 * nh3: 0.2.14
 * python-dateutil: 2.8.2
 * social-auth-core: 4.5.0
 * social-auth-app-django: 5.4.0
 * django-crispy-forms: 2.1
 * oauthlib: 3.2.2
 * django-compressor: 4.4
 * djangorestframework: 3.14.0
 * django-filter: 23.3
 * django-appconf: 1.0.5
 * user-agents: 2.2.0
 * filelock: 3.13.1
 * rapidfuzz: 3.5.2
 * openpyxl: 3.1.2
 * celery: 5.3.5
 * django-celery-beat: 2.5.0
 * kombu: 5.3.4
 * translation-finder: 2.15
 * weblate-language-data: 2023.6
 * html2text: 2020.1.16
 * pycairo: 1.25.1
 * PyGObject: 3.46.0
 * diff-match-patch: 20230430
 * requests: 2.31.0
 * django-redis: 5.4.0
 * hiredis: 2.2.3
 * sentry-sdk: 1.35.0
 * Cython: 3.0.5
 * misaka: 2.1.1
 * GitPython: 3.1.40
 * borgbackup: 1.2.6
 * pyparsing: 3.1.1
 * ahocorasick_rs: 0.20.0
 * python-redis-lock: 4.0.0
 * charset-normalizer: 3.3.2
 * Python: 3.11.5
 * Git: 2.39.2
 * psycopg: 3.1.12
 * psycopg-binary: 3.1.12
 * phply: 1.2.6
 * ruamel.yaml: 0.18.5
 * tesserocr: 2.6.2
 * boto3: 1.29.2
 * zeep: 4.2.1
 * aeidon: 1.13
 * iniparse: 0.5
 * mysqlclient: 2.2.0
 * Mercurial: 6.5.3
 * git-svn: 2.39.2
 * git-review: 2.3.1
 * PostgreSQL server: 13.13
 * Database backends: django.db.backends.postgresql
 * PostgreSQL implementation: psycopg3 (binary)
 * Cache backends: default:RedisCache, avatar:FileBasedCache
 * Email setup: django.core.mail.backends.smtp.EmailBackend: smtp.office365.com
 * OS encoding: filesystem=utf-8, default=utf-8
 * Celery: redis://cache:6379/1, redis://cache:6379/1, regular
 * Platform: Linux 5.4.0-1109-azure (x86_64)
```

### Weblate deploy checks

```shell
System check identified some issues:

INFOS:
?: (weblate.I021) Error collection is not set up, it is highly recommended for production use
        HINT: https://docs.weblate.org/en/weblate-5.2/admin/install.html#collecting-errors
?: (weblate.I028) Backups are not configured, it is highly recommended for production use
        HINT: https://docs.weblate.org/en/weblate-5.2/admin/backup.html
?: (weblate.I031) New Weblate version is available, please upgrade to 5.2.1.
        HINT: https://docs.weblate.org/en/weblate-5.2/admin/upgrade.html

System check identified 3 issues (1 silenced).
```


### Additional context

Our instance is counting :
- 97 components
- 16 projects


Discussion:
With help of the provided trace and error message while attempting to translate strings using cli, I recreate the component using same source language as the other project component.

Now, I got access to the component list and everything is working fine.

So, I think there are two issues here :

- the error does not provide enough information as the cli does which might lead the end user to the proper path
- there are no information that help end user to know why he does not access to components

Resolving patch:
diff --git a/weblate/trans/forms.py b/weblate/trans/forms.py
--- a/weblate/trans/forms.py
+++ b/weblate/trans/forms.py
@@ -874,7 +874,7 @@ class AutoForm(forms.Form):
         initial="others",
     )
     component = forms.ChoiceField(
-        label=gettext_lazy("Components"),
+        label=gettext_lazy("Component"),
         required=False,
         help_text=gettext_lazy(
             "Turn on contribution to shared translation memory for the project to "
@@ -994,6 +994,12 @@ def clean_component(self):
                     raise ValidationError(gettext("Component not found!"))
             else:
                 raise ValidationError(gettext("Please provide valid component slug!"))
+        if result.source_language != self.obj.source_language:
+            raise ValidationError(
+                gettext(
+                    "Source component needs to have same source language as target one."
+                )
+            )
         return result.pk
 
 


Test patch: