Repository: learningequality/kolibri

Issue:
names of CSV files should be internationalized

### Observed behavior

The names of files when exporting and downloading from the facility data page are all in English:

> ![image](https://user-images.githubusercontent.com/2367265/81123607-52be9500-8ee8-11ea-907b-ab8300d24f20.png)

![image](https://user-images.githubusercontent.com/2367265/81123553-302c7c00-8ee8-11ea-8bb6-ea54ed2e376d.png)

ref: https://github.com/learningequality/kolibri/pull/6835

### Expected behavior

Names of files should be in the user's currently selected language. This is the same behavior as currently exists in Coach CSV export.

### User-facing consequences

file name meaning is not understandable in the user's preferred language

### Context

0.13.2


Discussion:

Resolving patch:
diff --git a/kolibri/core/logger/csv_export.py b/kolibri/core/logger/csv_export.py
--- a/kolibri/core/logger/csv_export.py
+++ b/kolibri/core/logger/csv_export.py
@@ -13,6 +13,10 @@
 from django.http import Http404
 from django.http import HttpResponse
 from django.http.response import FileResponse
+from django.template.defaultfilters import slugify
+from django.utils import translation
+from django.utils.translation import get_language_from_request
+from django.utils.translation import pgettext
 
 from .models import ContentSessionLog
 from .models import ContentSummaryLog
@@ -180,6 +184,29 @@ def exported_logs_info(request):
 
 
 def download_csv_file(request, log_type):
+    locale = get_language_from_request(request)
+    translation.activate(locale)
+
+    csv_translated_filenames = {
+        "session": (
+            slugify(
+                pgettext(
+                    "Default name for the exported CSV file with content session logs. Please keep the underscores between words in the translation",
+                    "content_session_logs",
+                )
+            )
+            + ".csv"
+        ).replace("-", "_"),
+        "summary": (
+            slugify(
+                pgettext(
+                    "Default name for the exported CSV file with content summary logs. Please keep the underscores between words in the translation",
+                    "content_summary_logs",
+                )
+            )
+            + ".csv"
+        ).replace("-", "_"),
+    }
     csv_export_filenames = {
         "session": "content_session_logs.csv",
         "summary": "content_summary_logs.csv",
@@ -202,8 +229,9 @@ def download_csv_file(request, log_type):
 
     # set the content-disposition as attachment to force download
     response["Content-Disposition"] = "attachment; filename={}".format(
-        csv_export_filenames[log_type]
+        str(csv_translated_filenames[log_type])
     )
+    translation.deactivate()
 
     # set the content-length to the file size
     response["Content-Length"] = os.path.getsize(filepath)
diff --git a/kolibri/plugins/facility/views.py b/kolibri/plugins/facility/views.py
--- a/kolibri/plugins/facility/views.py
+++ b/kolibri/plugins/facility/views.py
@@ -8,7 +8,11 @@
 
 from django.http import Http404
 from django.http.response import FileResponse
+from django.template.defaultfilters import slugify
+from django.utils import translation
 from django.utils.decorators import method_decorator
+from django.utils.translation import get_language_from_request
+from django.utils.translation import pgettext
 from django.views.generic.base import TemplateView
 
 from kolibri.core.decorators import cache_no_user_data
@@ -21,6 +25,8 @@ class FacilityManagementView(TemplateView):
 
 
 def download_csv_file(request, filename):
+    locale = get_language_from_request(request)
+    translation.activate(locale)
     filepath = os.path.join(conf.KOLIBRI_HOME, "temp", filename)
 
     # if the file does not exist on disk, return a 404
@@ -33,11 +39,21 @@ def download_csv_file(request, filename):
     response["Content-Type"] = "text/csv"
 
     # set the content-disposition as attachment to force download
-    response["Content-Disposition"] = "attachment; filename=users_{}.csv".format(
-        datetime.now().strftime("%Y%m%d_%H%M%S")
+    exported_filename = (
+        slugify(
+            pgettext(
+                "Default name for the exported CSV file of facility user data. Please keep the underscore between words in the translation",
+                "users_{}",
+            ).format(datetime.now().strftime("%Y%m%d_%H%M%S"))
+        ).replace("-", "_")
+        + ".csv"
+    )
+    response["Content-Disposition"] = "attachment; filename={}".format(
+        str(exported_filename)
     )
 
     # set the content-length to the file size
     response["Content-Length"] = os.path.getsize(filepath)
+    translation.deactivate()
 
     return response


Test patch: