Repository: WeblateOrg/weblate

Issue:
Creating terminology entry crashes if it exists in another language
### Describe the issue

If some glossary string has been create in other language, we can't use Terminology option (String will be part of the glossary in all languages) 

![image](https://github.com/WeblateOrg/weblate/assets/6064962/b3d3498c-2082-4104-bb48-f557db95f386)

Raise from: https://github.com/aseprite/languages/issues/28

### 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

![image](https://github.com/WeblateOrg/weblate/assets/6064962/3fbb3f52-c618-45ed-b18c-d48e2cbc5ed5)


### Expected behavior

_No response_

### Screenshots

_No response_

### Exception traceback

_No response_

### How do you run Weblate?

weblate.org service

### Weblate versions

_No response_

### Weblate deploy checks

_No response_

### Additional context

_No response_


Discussion:
You can mark existing string as a terminology instead of adding new one.
This issue has been automatically marked as stale because there wasn’t any recent activity.

It will be closed soon if no further action occurs.

Thank you for your contributions!
Sentry issue: [WEBLATE-2NK](https://sentry.weblate.org/organizations/weblate/issues/2967/?referrer=github_integration)
Sentry issue: [WEBLATE-5AM](https://sentry.weblate.org/organizations/weblate/issues/5887/?referrer=github_integration)

Resolving patch:
diff --git a/weblate/glossary/forms.py b/weblate/glossary/forms.py
--- a/weblate/glossary/forms.py
+++ b/weblate/glossary/forms.py
@@ -123,4 +123,5 @@ def as_kwargs(self):
             "auto_context": True,
             "extra_flags": self.get_glossary_flags(),
             "explanation": self.cleaned_data.get("explanation"),
+            "skip_existing": bool(self.cleaned_data.get("terminology")),
         }
diff --git a/weblate/trans/models/translation.py b/weblate/trans/models/translation.py
--- a/weblate/trans/models/translation.py
+++ b/weblate/trans/models/translation.py
@@ -1619,6 +1619,7 @@ def validate_new_unit_data(
         extra_flags: str | None = None,
         explanation: str = "",
         state: int | None = None,
+        skip_existing: bool = False,
     ):
         component = self.component
         extra = {}


Test patch:
diff --git a/weblate/glossary/tests.py b/weblate/glossary/tests.py
--- a/weblate/glossary/tests.py
+++ b/weblate/glossary/tests.py
@@ -322,15 +322,18 @@ def test_get_single(self):
             unit_sources_and_positions(get_glossary_terms(unit)), {("thank", ((0, 5),))}
         )
 
-    def do_add_unit(self, **kwargs):
-        unit = self.get_unit("Thank you for using Weblate.")
+    def do_add_unit(self, language="cs", **kwargs):
+        unit = self.get_unit("Thank you for using Weblate.", language=language)
+        glossary = self.glossary_component.translation_set.get(
+            language=unit.translation.language
+        )
         # Add term
         response = self.client.post(
             reverse("js-add-glossary", kwargs={"unit_id": unit.pk}),
             {
                 "source": "source",
                 "target": "překlad",
-                "translation": self.glossary.pk,
+                "translation": glossary.pk,
                 **kwargs,
             },
         )
@@ -350,6 +353,16 @@ def test_add_terminology(self):
         # Should be added to all languages
         self.assertEqual(Unit.objects.count(), start + 4)
 
+    def test_add_terminology_existing(self):
+        self.make_manager()
+        start = Unit.objects.count()
+        # Add unit to other translation
+        self.do_add_unit(language="it")
+        # Add terminology to translation where unit does not exist
+        self.do_add_unit(terminology=1)
+        # Should be added to all languages
+        self.assertEqual(Unit.objects.count(), start + 4)
+
     def test_add_duplicate(self):
         self.do_add_unit()
         self.do_add_unit()