Repository: WeblateOrg/weblate

Issue:
Differentiate translations created by Prefill add-on
### Describe the problem

It’s hard to monitor changes in translations and not lose some strings when using the `Prefill translation with source` add-on. Controlling the target status should be an option.

### Describe the solution you'd like

EDIT: https://github.com/WeblateOrg/weblate/issues/9294#issuecomment-1564017068

~Let the user set the target status of the strings pre-filled by this add-on like it is possible with `mode` in `Automatic translation`.~

~`Untranslated` and `Needs editing` statuses are desired.~

### Describe alternatives you've considered

_No response_

### Screenshots

_No response_

### Additional context

_No response_


Discussion:
*Untranslated* state is only applicable to blank strings.
This issue seems to be a good fit for newbie contributors. You are welcome to contribute to Weblate! Don't hesitate to ask any questions you would have while implementing this.

You can learn about how to get started in our [contributors documentation](https://docs.weblate.org/en/latest/contributing/index.html).
do we need to customize the translations part with editing option.
@ashishnagar19 Can you please clarify what you mean?
I am trying to say if strings does'nt get translated or there is some error in target, do we need to give users a option to edit further.
> I am trying to say if strings does'nt get translated or there is some error in target, do we need to give users a option to edit further.

This issue is about letting the user adjust what status will be used for the translations pre-filled by this add-on: https://docs.weblate.org/en/latest/admin/addons.html#prefill-translation-with-source

The default (current) status is `Needs editing`.


After consultations, we defined a better way to implement this and solve problems that led to this issue. Strings pre-filled by this add-on will have label `Prefilled with source`
All translations created by this add-on will be labeled automatically with `Prefilled with source`

Letting choose a state for prefilled translations doesn’t make sense until https://github.com/WeblateOrg/weblate/issues/2240#issuecomment-737763753 is implemented. The only reasonable state from available ones is `Needs editing`. Once that is broken into multiple variants, a choice here could make sense.
Thinking more about this, adding label is not the right approach here. The proper solution really is splitting "Needs editing" into substates, as described in #2240.

Resolving patch:
diff --git a/weblate/addons/base.py b/weblate/addons/base.py
--- a/weblate/addons/base.py
+++ b/weblate/addons/base.py
@@ -49,6 +49,8 @@ class BaseAddon:
     alert: str | None = None
     trigger_update = False
     stay_on_create = False
+    user_name = ""
+    user_verbose = ""
 
     def __init__(self, storage=None):
         self.instance = storage
@@ -329,6 +331,20 @@ def pre_install(cls, component, request):
                     ),
                 )
 
+    @cached_property
+    def user(self):
+        """Weblate user used to track changes by this add-on."""
+        from weblate.auth.models import User
+
+        if not self.user_name or not self.user_verbose:
+            raise ValueError(
+                f"{self.__class__.__name__} is missing user_name and user_verbose!"
+            )
+
+        return User.objects.get_or_create_bot(
+            "addon", self.user_name, self.user_verbose
+        )
+
 
 class TestAddon(BaseAddon):
     """Testing add-on doing nothing."""
diff --git a/weblate/addons/generate.py b/weblate/addons/generate.py
--- a/weblate/addons/generate.py
+++ b/weblate/addons/generate.py
@@ -97,7 +97,7 @@ def generate_translation(
             target_strings = unit.get_target_plurals()
             if new_strings != target_strings or unit.state < STATE_TRANSLATED:
                 unit.translate(
-                    None,
+                    self.user,
                     new_strings,
                     target_state,
                     change_action=Change.ACTION_AUTO,
@@ -122,6 +122,8 @@ class PseudolocaleAddon(LocaleGenerateAddonBase):
         "to source strings automatically."
     )
     settings_form = PseudolocaleAddonForm
+    user_name = "pseudolocale"
+    user_verbose = "Pseudolocale add-on"
 
     def daily(self, component):
         # Check all strings
@@ -186,6 +188,8 @@ class PrefillAddon(LocaleGenerateAddonBase):
     name = "weblate.generate.prefill"
     verbose = gettext_lazy("Prefill translation with source")
     description = gettext_lazy("Fills in translation strings with source string.")
+    user_name = "prefill"
+    user_verbose = "Prefill add-on"
 
     def daily(self, component):
         # Check all strings
@@ -217,6 +221,8 @@ class FillReadOnlyAddon(LocaleGenerateAddonBase):
     description = gettext_lazy(
         "Fills in translation of read-only strings with source string."
     )
+    user_name = "fill"
+    user_verbose = "Fill read-only add-on"
 
     def daily(self, component):
         self.do_update(component)


Test patch: