internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: WeblateOrg/weblate

Issue:
Document weblate migrate command
### Describe the problem

`weblate migrate` command is mentioned in the docs, but not actually documented. 

It is also used inconsistently:
1. https://docs.weblate.org/en/latest/admin/languages.html#built-in-language-definitions
2. https://docs.weblate.org/en/latest/admin/install.html#filling-up-the-database

### Describe the solution you'd like

document the usage and link it in mentioned occurrences.

### Describe alternatives you've considered

_No response_

### Screenshots

_No response_

### Additional context

_No response_


Discussion:

Resolving patch:
diff --git a/docs/_ext/djangodocs.py b/docs/_ext/djangodocs.py
--- a/docs/_ext/djangodocs.py
+++ b/docs/_ext/djangodocs.py
@@ -1,6 +1,7 @@
 """Sphinx plugins for Weblate documentation."""
 import re
 
+from docutils.nodes import literal
 from sphinx import addnodes
 from sphinx.domains.std import Cmdoption
 
@@ -8,22 +9,45 @@
 simple_option_desc_re = re.compile(r"([-_a-zA-Z0-9]+)(\s*.*?)(?=,\s+(?:/|-|--)|$)")
 
 
+class WeblateCommandLiteral(literal):
+    def __init__(self, rawsource="", text="", *children, **attributes):
+        if not text:
+            text = "weblate "
+        super().__init__(rawsource, text, *children, **attributes)
+
+
 def setup(app):
     app.add_crossref_type(
         directivename="setting", rolename="setting", indextemplate="pair: %s; setting"
     )
+    app.add_object_type(
+        directivename="weblate-admin",
+        rolename="wladmin",
+        indextemplate="pair: %s; weblate admin command",
+        parse_node=parse_weblate_admin_node,
+        ref_nodeclass=WeblateCommandLiteral,
+    )
+    app.add_directive("weblate-admin-option", Cmdoption)
     app.add_object_type(
         directivename="django-admin",
         rolename="djadmin",
-        indextemplate="pair: %s; weblate admin command",
+        indextemplate="pair: %s; django-admin command",
         parse_node=parse_django_admin_node,
     )
-    app.add_directive("django-admin-option", Cmdoption)
 
 
-def parse_django_admin_node(env, sig, signode):
+def parse_weblate_admin_node(env, sig, signode):
     command = sig.split(" ")[0]
+    # Context for options
     env.ref_context["std:program"] = command
     title = f"weblate {sig}"
     signode += addnodes.desc_name(title, title)
     return command
+
+
+def parse_django_admin_node(env, sig, signode):
+    command = sig.split(" ")[0]
+    env.ref_context["std:program"] = command
+    title = "django-admin %s" % sig
+    signode += addnodes.desc_name(title, title)
+    return command


Test patch:
Repository: WeblateOrg/weblate

Issue:
Glossary translation explanation mapping is broken
### Describe the issue

We are using TBX glossary and there is a bug when the TBX gets updated and Weblate pulls changes from the repo.

When we add new glossary entry in Weblate, the explanation is written as `<descrip>` for source unit explanation and as `<note from="translator">` for target unit explanation.

However when we modify TBX in the VCS and pull the changes, everything from the TBX file gets mapped to `note` column in the database. So we end up with duplicate explanations that can not be deleted via UI.

### 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. Create new translation project
2. Create glossary component
3. Add new glossary entry with source string explanation
4. Push to repository
5. Make new commit in the repository by changing glossary translation
6. Pull changes to Weblate (update from repo)
7. Observe duplicate explanation that can no longer be edited

### Expected behavior

Source string explanation and translation explanation should be mapped to `explanation` only and `note` should no longer be used.

### Screenshots

![obrazek](https://github.com/WeblateOrg/weblate/assets/2012726/c21dee92-78d6-48bd-ad82-3dd42a68b614)


### Exception traceback

_No response_

### How do you run Weblate?

Docker container

### Weblate versions

4.18.1

### Weblate deploy checks

_No response_

### Additional context

_No response_


Discussion:
The issue you've reported needs to be addressed in the [translate-toolkit](https://github.com/translate/translate/). Please file the issue there, and include links to any relevant specifications about the formats (if applicable).
Ah, translate-toolkit sets the `from` attribute `note` when saving this, but does no filtering when reading. Needs to be fixed there.
> Ah, translate-toolkit sets the `from` attribute `note` when saving this, but does no filtering when reading. Needs to be fixed there.

Should I create the issue there? I am not sure I understand the cause you've described.

Resolving patch:
diff --git a/weblate/formats/ttkit.py b/weblate/formats/ttkit.py
--- a/weblate/formats/ttkit.py
+++ b/weblate/formats/ttkit.py
@@ -1935,7 +1935,7 @@ def set_explanation(self, explanation: str):
 
     @cached_property
     def explanation(self) -> str:
-        return self._get_notes("definition")
+        return self._get_notes("translator")
 
     def set_source_explanation(self, explanation: str):
         if explanation or self.source_explanation:
@@ -1944,7 +1944,7 @@ def set_source_explanation(self, explanation: str):
 
     @cached_property
     def source_explanation(self) -> str:
-        return self._get_notes("source-explanation")
+        return self._get_notes("definition")
 
 
 class TBXFormat(TTKitFormat):


Test patch:
Repository: WeblateOrg/weblate

Issue:
Documentation missing for support GIF screenshots
Using Weblate 4.18.1
### Describe the problem

Screenshots are good to provide the context of a string to the users.
Sometimes the context is not clear from an one-frame image. Sometimes there is a need of a short GIF animation.
See example below.

### Describe the solution you'd like

Support animated GIFs as upload option to screenshots section.

### Describe alternatives you've considered

_No response_

### Screenshots

Here you see one tooltip. The content of that tooltip is modified depending on context.

![bit_fileview_tooltips](https://github.com/WeblateOrg/weblate/assets/11861496/b8457944-5dca-4a64-9b60-1b966cdcdf17)


### Additional context

_No response_


Discussion:

Resolving patch:
diff --git a/weblate/screenshots/migrations/0007_alter_screenshot_image.py b/weblate/screenshots/migrations/0007_alter_screenshot_image.py
new file mode 100644
--- /dev/null
+++ b/weblate/screenshots/migrations/0007_alter_screenshot_image.py
@@ -0,0 +1,27 @@
+# Copyright © Michal Čihař <michal@weblate.org>
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+# Generated by Django 4.2.3 on 2023-07-17 08:01
+
+from django.db import migrations
+
+import weblate.screenshots.fields
+
+
+class Migration(migrations.Migration):
+    dependencies = [
+        ("screenshots", "0006_screenshot_repository_filename"),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name="screenshot",
+            name="image",
+            field=weblate.screenshots.fields.ScreenshotField(
+                help_text="Upload image up to 2000x2000 pixels.",
+                upload_to="screenshots/",
+                verbose_name="Image",
+            ),
+        ),
+    ]
diff --git a/weblate/screenshots/models.py b/weblate/screenshots/models.py
--- a/weblate/screenshots/models.py
+++ b/weblate/screenshots/models.py
@@ -55,7 +55,7 @@ class Screenshot(models.Model, UserDisplayMixin):
     )
     image = ScreenshotField(
         verbose_name=gettext_lazy("Image"),
-        help_text=gettext_lazy("Upload JPEG or PNG images up to 2000x2000 pixels."),
+        help_text=gettext_lazy("Upload image up to 2000x2000 pixels."),
         upload_to="screenshots/",
     )
     translation = models.ForeignKey(Translation, on_delete=models.deletion.CASCADE)


Test patch:
Repository: WeblateOrg/weblate

Issue:
Display XLF context information in Web interface
### Describe the problem

Hello,

Given the trans-unit from XLF below :

```xml
<trans-unit id="9047795109808746529" datatype="html">
	<source>Hello</source>
	<target state="new">Hello</target>
	<context-group purpose="location">
	  <context context-type="sourcefile">src/a.html</context>
	  <context context-type="linenumber">251,253</context>
	</context-group>
	<context-group purpose="location">
	  <context context-type="sourcefile">src/b.html</context>
	  <context context-type="linenumber">742,744</context>
	</context-group>
</trans-unit>
```

I would expect to have contexts displayed in weblate web interface to be able to quickly find from where the translation come from in the code.


Is there a way to display this ?
Othewise it would be a useful feature.


### Describe the solution you'd like

To have sourcefile and linenumber would be helpful for translation.

### Describe alternatives you've considered

_No response_

### Screenshots

_No response_

### Additional context

_No response_


Discussion:
The issue you've reported needs to be addressed in the [translate-toolkit](https://github.com/translate/translate/). Please file the issue there, and include links to any relevant specifications about the formats (if applicable).
We're having the same inconvenience on our projects. :-) Would be really helpful to have this information displayed on the web interface.
First, translate-toolkit needs to support querying context groups by purpose here: https://github.com/translate/translate/blob/cc9a7b8fa4089399150a4605c1438c29897538bc/translate/storage/xliff.py#L542-L562. Once this is done, support in Weblate can be added.
Hi,

i implemented the function for this into the translate-toolkit (https://github.com/translate/translate/pull/4948). 

i tried to include the new functionality into weblate, but i couldn't get the weblate development setup to run, so i didn't get a chance to test it directly in weblate, but here would be the code for weblate:

https://github.com/WeblateOrg/weblate/blob/6000024dcfa9a5c48248d17856f5ae33bcef1772/weblate/formats/ttkit.py#L640
```py
    @cached_property
    def locations(self):
        """Return comma separated list of locations."""
        locations = []
        for contextGroup in self.mainunit.getcontextgroupsbyattribute("purpose", "location"):
            for context in contextGroup:
                if len(context) == 2:
                    locations.append(context[0][1] + ":" + context[1][1])

        return ", ".join(x for x in locations if x is not None)
```


Resolving patch:
diff --git a/weblate/formats/ttkit.py b/weblate/formats/ttkit.py
--- a/weblate/formats/ttkit.py
+++ b/weblate/formats/ttkit.py
@@ -638,11 +638,6 @@ def context(self):
             return resname
         return self.mainunit.getid().replace(ID_SEPARATOR, "///")
 
-    @cached_property
-    def locations(self):
-        """Return comma separated list of locations."""
-        return ""
-
     def is_translated(self):
         """
         Check whether unit is translated.


Test patch:
Repository: WeblateOrg/weblate

Issue:
read-only flagged translation strings trigger reused QA check for empty translations
### Describe the issue

In a project using gettext po files I have marked some strings that are for technical reasons included in the translation files but should actually stay unchanged as `read-only`. Now these string also consider the "reused" warning with other read-only strings as they all share the empty translation.

As a workaround I can use of course `ignore-reused` on those strings.


### 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. Add read-only to multiple not yet translated strings

### Expected behavior

Setting to `read-only` should not trigger reused if empty.

### Screenshots

_No response_

### Exception traceback

_No response_

### How do you run Weblate?

self-hosted

### Weblate versions

Weblate 4.18.2

### Weblate deploy checks

_No response_

### Additional context

_No response_


Discussion:
Example: https://translate.uploadedlobster.com/translate/picard-docs/variablestags_advanced/de/?q=has:check

Resolving patch:
diff --git a/weblate/checks/consistency.py b/weblate/checks/consistency.py
--- a/weblate/checks/consistency.py
+++ b/weblate/checks/consistency.py
@@ -164,7 +164,7 @@ def get_propagated_units(self, unit, target: str | None = None):
         return Unit.objects.same_target(unit, target)
 
     def should_skip(self, unit):
-        if unit.translation.plural.number <= 1:
+        if unit.translation.plural.number <= 1 or not any(unit.get_target_plurals()):
             return True
         return super().should_skip(unit)
 
@@ -201,6 +201,7 @@ def check_component(self, component):
             translation__component__allow_translation_propagation=True,
             state__gte=STATE_TRANSLATED,
         )
+        units = units.exclude(target="")
 
         # List strings with different sources
         # Limit this to 100 strings, otherwise the resulting query is way too complex


Test patch:
Repository: WeblateOrg/weblate

Issue:
"Add missing languages" add-on not working
### Describe the issue

I have enabled the "Add missing languages" add-on on https://hosted.weblate.org/projects/catima/. However, despite waiting over 24 hours as the documentation on https://docs.weblate.org/en/latest/admin/addons.html#addon-weblate-consistency-languages states, it has not put the different components of the same project in sync.

This is most noticeable when comparing https://hosted.weblate.org/projects/catima/catima/ with https://hosted.weblate.org/projects/catima/android-debug/

### 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. Enable the "Add missing languages" add-on in a project with multiple components where one component has less languages than the other
2. Wait at least 24 hours as the add-on states

### Expected behavior

All components have the same languages, missing languages on components get created

### Screenshots

Android component:
![image](https://github.com/WeblateOrg/weblate/assets/1885159/bae7c490-381f-4e13-a025-97c0a1494c01)

Android (Debug) component:
![image](https://github.com/WeblateOrg/weblate/assets/1885159/03230fe9-c0a4-44e6-9dbe-ced43868fb69)


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

Resolving patch:
diff --git a/weblate/addons/consistency.py b/weblate/addons/consistency.py
--- a/weblate/addons/consistency.py
+++ b/weblate/addons/consistency.py
@@ -2,13 +2,11 @@
 #
 # SPDX-License-Identifier: GPL-3.0-or-later
 
-from django.db.models import Q
 from django.utils.translation import gettext_lazy
 
 from weblate.addons.base import BaseAddon
 from weblate.addons.events import EVENT_DAILY, EVENT_POST_ADD
 from weblate.addons.tasks import language_consistency
-from weblate.lang.models import Language
 
 
 class LangaugeConsistencyAddon(BaseAddon):
@@ -25,11 +23,7 @@ class LangaugeConsistencyAddon(BaseAddon):
     def daily(self, component):
         language_consistency.delay(
             component.project_id,
-            list(
-                Language.objects.filter(
-                    Q(translation__component=component) | Q(component=component)
-                ).values_list("pk", flat=True)
-            ),
+            [language.id for language in component.project.languages],
         )
 
     def post_add(self, translation):


Test patch:
Repository: WeblateOrg/weblate

Issue:
Numbers for project/languages are inflated (Unfinished, Unfinished words, Unfinished characters, Untranslated, Checks, Suggestions)
### Describe the issue

Since a couple of weeks I think, the numbers in the Languages section of our project are terribly inflated.

See for example the numbers for Spanish: https://hosted.weblate.org/projects/tor/#languages and compare with the numbers that appear at https://hosted.weblate.org/projects/tor/-/es/ - there are many more Unfinished, Unfinished words, Unfinished characters, Untranslated, Checks, and Suggestions in the first link.

I seem to remember that this inflated numbers came to be in the same release than the Categories.

### 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 https://hosted.weblate.org/projects/tor/#languages
2. Count the suggestions for Spanish
3. Click on 'Spanish' and go to https://hosted.weblate.org/projects/tor/-/es/
4. Count the suggestions

The number is different. Same with the other values mentioned.

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

Resolving patch:
diff --git a/weblate/utils/stats.py b/weblate/utils/stats.py
--- a/weblate/utils/stats.py
+++ b/weblate/utils/stats.py
@@ -1141,9 +1141,6 @@ def object_set(self):
 
 class CategoryStats(ParentAggregatingStats):
     def get_update_objects(self):
-        yield self._object.project.stats
-        yield from self._object.project.stats.get_update_objects()
-
         if self._object.category:
             yield self._object.category.stats
             yield from self._object.category.stats.get_update_objects()
@@ -1178,12 +1175,6 @@ class ProjectStats(ParentAggregatingStats):
     def has_review(self):
         return self._object.enable_review
 
-    @cached_property
-    def category_set(self):
-        return prefetch_stats(
-            self._object.category_set.filter(category=None).only("id", "project")
-        )
-
     @cached_property
     def object_set(self):
         return prefetch_stats(


Test patch:
Repository: WeblateOrg/weblate

Issue:
Some languages don't have all strings available for translation
### Describe the issue

My project is here: https://hosted.weblate.org/projects/feeder/android-strings

A few languages Polish, French and Chinese (Simplified), are missing a dozen strings.

One example is the string `other_minutes` which is not available for translation in these languages.

I have tried re-scanning strings and similar with no change.

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

Not sure how to reproduce it but it is happening here :https://hosted.weblate.org/projects/feeder/android-strings

look at string `other_minutes`, it is missing from Polish, French, and Chinese (Simplified)

### Expected behavior

All strings should be available for translation in all languages.

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

Resolving patch:
diff --git a/weblate/addons/cleanup.py b/weblate/addons/cleanup.py
--- a/weblate/addons/cleanup.py
+++ b/weblate/addons/cleanup.py
@@ -34,7 +34,7 @@ def update_translations(self, component, previous_head):
             if filenames is None:
                 continue
             self.extra_files.extend(filenames)
-            translation.store_hash()
+            # Do not update hash here as this is just before parsing updated files
 
     def pre_commit(self, translation, author):
         if translation.is_source and not translation.component.intermediate:
@@ -63,7 +63,9 @@ def update_translations(self, component, previous_head):
             if filenames is None:
                 continue
             self.extra_files.extend(filenames)
-            translation.store_hash()
+            # Do not update hash in post_update, only in post_commit
+            if previous_head == "weblate:post-commit":
+                translation.store_hash()
 
     def post_commit(self, component):
-        self.post_update(component, None, skip_push=True)
+        self.post_update(component, "weblate:post-commit", skip_push=True)


Test patch:
Repository: WeblateOrg/weblate

Issue:
Background commit of pending changes might be late
### Describe the issue

The `commit_pending` might not commit pending changes when desired because it looks at the timestamp of the most recent change instead of looking at the oldest pending change:

https://github.com/WeblateOrg/weblate/blob/2f2bdfbb52ac36c7a912072b36e14547fb316d16/weblate/trans/tasks.py#L114-L144

### I already tried

- [X] I've read and searched [the documentation](https://docs.weblate.org/).
- [X] I've searched for similar filed issues in this repository.

### Steps to reproduce the behavior

1. Update a translation by a single user frequently enough to be under `commit_pending_age`.
2. See that the changes are never committed.

### Expected behavior

Changes should be committed based on the oldest change.

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

Resolving patch:
diff --git a/weblate/trans/models/component.py b/weblate/trans/models/component.py
--- a/weblate/trans/models/component.py
+++ b/weblate/trans/models/component.py
@@ -3295,11 +3295,15 @@ def get_ambiguous_translations(self):
         return self.translation_set.filter(language__code__in=AMBIGUOUS.keys())
 
     @property
-    def count_pending_units(self):
-        """Check for uncommitted changes."""
+    def pending_units(self):
         from weblate.trans.models import Unit
 
-        return Unit.objects.filter(translation__component=self, pending=True).count()
+        return Unit.objects.filter(translation__component=self, pending=True)
+
+    @property
+    def count_pending_units(self):
+        """Check for uncommitted changes."""
+        return self.pending_units.count()
 
     @property
     def count_repo_missing(self):
diff --git a/weblate/trans/tasks.py b/weblate/trans/tasks.py
--- a/weblate/trans/tasks.py
+++ b/weblate/trans/tasks.py
@@ -129,13 +129,14 @@ def commit_pending(hours=None, pks=None, logger=None):
         else:
             age = timezone.now() - timedelta(hours=hours)
 
-        last_change = component.stats.last_changed
-        if not last_change:
-            continue
-        if last_change > age:
+        units = component.pending_units.prefetch_recent_content_changes()
+
+        # No pending units
+        if not units:
             continue
 
-        if not component.needs_commit():
+        # All pending units are recent
+        if all(unit.recent_content_changes[0].timestamp > age for unit in units):
             continue
 
         if logger:


Test patch: