Repository: WeblateOrg/weblate

Issue:
Specified filename for translation downloads
Right now it is translations.zip, which leads to a lot of "translations(1).zip", "translations(2).zip", without a good way to tell what is what.


Discussion:

Resolving patch:
diff --git a/weblate/trans/views/files.py b/weblate/trans/views/files.py
--- a/weblate/trans/views/files.py
+++ b/weblate/trans/views/files.py
@@ -42,7 +42,7 @@
 )
 
 
-def download_multi(translations, fmt=None):
+def download_multi(translations, fmt=None, name="translations"):
     filenames = set()
     components = set()
 
@@ -64,7 +64,7 @@ def download_multi(translations, fmt=None):
                 if os.path.exists(fullname):
                     filenames.add(fullname)
 
-    return zip_download(data_dir("vcs"), sorted(filenames))
+    return zip_download(data_dir("vcs"), sorted(filenames), name)
 
 
 def download_component_list(request, name):
@@ -73,14 +73,20 @@ def download_component_list(request, name):
     for component in components:
         component.commit_pending("download", None)
     return download_multi(
-        Translation.objects.filter(component__in=components), request.GET.get("format")
+        Translation.objects.filter(component__in=components),
+        request.GET.get("format"),
+        name=obj.slug,
     )
 
 
 def download_component(request, project, component):
     obj = get_component(request, project, component)
     obj.commit_pending("download", None)
-    return download_multi(obj.translation_set.all(), request.GET.get("format"))
+    return download_multi(
+        obj.translation_set.all(),
+        request.GET.get("format"),
+        name=obj.full_slug.replace("/", "-"),
+    )
 
 
 def download_project(request, project):
@@ -88,7 +94,9 @@ def download_project(request, project):
     obj.commit_pending("download", None)
     components = obj.component_set.filter_access(request.user)
     return download_multi(
-        Translation.objects.filter(component__in=components), request.GET.get("format")
+        Translation.objects.filter(component__in=components),
+        request.GET.get("format"),
+        name=obj.slug,
     )
 
 
@@ -100,6 +108,7 @@ def download_lang_project(request, lang, project):
     return download_multi(
         Translation.objects.filter(component__in=components, language=langobj),
         request.GET.get("format"),
+        name=f"{obj.slug}-{langobj.code}",
     )
 
 
diff --git a/weblate/utils/views.py b/weblate/utils/views.py
--- a/weblate/utils/views.py
+++ b/weblate/utils/views.py
@@ -243,13 +243,13 @@ def iter_files(filenames):
             yield filename
 
 
-def zip_download(root, filenames):
+def zip_download(root, filenames, name="translations"):
     response = HttpResponse(content_type="application/zip")
     with ZipFile(response, "w") as zipfile:
         for filename in iter_files(filenames):
             with open(filename, "rb") as handle:
                 zipfile.writestr(os.path.relpath(filename, root), handle.read())
-    response["Content-Disposition"] = 'attachment; filename="translations.zip"'
+    response["Content-Disposition"] = f'attachment; filename="{name}.zip"'
     return response
 
 
@@ -285,7 +285,11 @@ def download_translation_file(translation, fmt=None, units=None):
             )
         else:
             extension = "zip"
-            response = zip_download(translation.get_filename(), filenames)
+            response = zip_download(
+                translation.get_filename(),
+                filenames,
+                translation.full_slug.replace("/", "-"),
+            )
 
         # Construct filename (do not use real filename as it is usually not
         # that useful)


Test patch: