Repository: learningequality/kolibri

Issue:
CSV headers headers for session and summary logs are not internationalized

### Observed behavior

Headers of the CSV data in session logs and summary logs are not internationalized:

![image](https://user-images.githubusercontent.com/2367265/77129874-dd1f6800-6a12-11ea-8397-1e0f28fcfd57.png)

![image](https://user-images.githubusercontent.com/2367265/77129903-f88a7300-6a12-11ea-9f1b-b7455eea8164.png)


### Expected behavior

Headers should be in the current language of the user that is triggering the export. This is consistent with our treatment of CSV file exports in Coach Reports

### User-facing consequences

Non-English-speaking users will have trouble using the CSV files


### Context

0.13.2


Discussion:
This can  not be done as it was done in the coach page as the export is done in the background in a task, not exporting the content of a table in the frontend.

Blocked by #10106

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
@@ -10,6 +10,8 @@
 
 from dateutil import parser
 from django.core.cache import cache
+from django.utils.translation import gettext_lazy as _
+from django.utils.translation import pgettext_lazy
 from le_utils.constants import content_kinds
 
 from .models import ContentSessionLog
@@ -64,18 +66,42 @@ def cache_content_title(obj):
 
 labels = OrderedDict(
     (
-        ("user__facility__name", "Facility name"),
-        ("user__username", "Username"),
-        ("channel_id", "Channel id"),
-        ("channel_name", "Channel name"),
-        ("content_id", "Content id"),
-        ("content_title", "Content title"),
-        ("start_timestamp", "Time of first interaction"),
-        ("end_timestamp", "Time of last interaction"),
-        ("completion_timestamp", "Time of completion"),
-        ("time_spent", "Time Spent (sec)"),
-        ("progress", "Progress (0-1)"),
-        ("kind", "Content kind"),
+        ("user__facility__name", _("Facility name")),
+        ("user__username", _("Username")),
+        ("channel_id", _("Channel id")),
+        ("channel_name", _("Channel name")),
+        ("content_id", _("Content id")),
+        ("content_title", _("Content title")),
+        (
+            "start_timestamp",
+            pgettext_lazy(
+                "CSV column header for the time of the first interaction in the exported logs",
+                "Time of first interaction",
+            ),
+        ),
+        (
+            "end_timestamp",
+            pgettext_lazy(
+                "CSV column header for the time of the last interaction in the exported logs",
+                "Time of last interaction",
+            ),
+        ),
+        (
+            "completion_timestamp",
+            pgettext_lazy(
+                "CSV column header for the percentage of completion in the exported logs",
+                "Time of completion",
+            ),
+        ),
+        (
+            "time_spent",
+            pgettext_lazy(
+                "CSV column header for the time spent in a resource in the exported logs",
+                "Time Spent (sec)",
+            ),
+        ),
+        ("progress", _("Progress (0-1)")),
+        ("kind", _("Content kind")),
     )
 )
 
diff --git a/kolibri/core/logger/management/commands/exportlogs.py b/kolibri/core/logger/management/commands/exportlogs.py
--- a/kolibri/core/logger/management/commands/exportlogs.py
+++ b/kolibri/core/logger/management/commands/exportlogs.py
@@ -90,7 +90,6 @@ def handle_async(self, *args, **options):
         # set language for the translation of the messages
         locale = settings.LANGUAGE_CODE if not options["locale"] else options["locale"]
         translation.activate(locale)
-
         self.overall_error = ""
         job = get_current_job()
 
diff --git a/kolibri/core/logger/tasks.py b/kolibri/core/logger/tasks.py
--- a/kolibri/core/logger/tasks.py
+++ b/kolibri/core/logger/tasks.py
@@ -31,11 +31,13 @@ class ExportLogCSVValidator(JobValidator):
     )
     start_date = serializers.CharField()
     end_date = serializers.CharField()
+    locale = serializers.CharField(required=False)
 
     def validate(self, data):
         facility = data.get("facility", None)
         start_date = data.get("start_date", None)
         end_date = data.get("end_date", None)
+        locale = data.get("locale", None)
 
         if facility is None and "user" in self.context:
             facility = self.context["user"].facility
@@ -53,6 +55,7 @@ def validate(self, data):
             "facility": facility.id,
             "start_date": start_date,
             "end_date": end_date,
+            "locale": locale,
         }
         return {
             "facility_id": facility.id,
@@ -61,7 +64,7 @@ def validate(self, data):
         }
 
 
-def _exportlogcsv(log_type, facility_id, start_date, end_date):
+def _exportlogcsv(log_type, facility_id, start_date, end_date, locale):
     filepath = get_filepath(log_type, facility_id, start_date, end_date)
     call_command(
         "exportlogs",
@@ -71,6 +74,7 @@ def _exportlogcsv(log_type, facility_id, start_date, end_date):
         overwrite=True,
         start_date=start_date,
         end_date=end_date,
+        locale=locale,
     )
 
 
@@ -86,7 +90,11 @@ def exportsessionlogcsv(facility_id, **kwargs):
     :param: facility.
     """
     _exportlogcsv(
-        "session", facility_id, kwargs.get("start_date"), kwargs.get("end_date")
+        "session",
+        facility_id,
+        kwargs.get("start_date"),
+        kwargs.get("end_date"),
+        kwargs.get("locale"),
     )
 
 
@@ -102,5 +110,9 @@ def exportsummarylogcsv(facility_id, **kwargs):
     :param: facility.
     """
     _exportlogcsv(
-        "summary", facility_id, kwargs.get("start_date"), kwargs.get("end_date")
+        "summary",
+        facility_id,
+        kwargs.get("start_date"),
+        kwargs.get("end_date"),
+        kwargs.get("locale"),
     )


Test patch:
diff --git a/kolibri/core/logger/test/test_tasks.py b/kolibri/core/logger/test/test_tasks.py
--- a/kolibri/core/logger/test/test_tasks.py
+++ b/kolibri/core/logger/test/test_tasks.py
@@ -35,6 +35,7 @@ def test_validator_sets_right_metadata(self):
                     "facility": self.facility.id,
                     "start_date": self.start_date,
                     "end_date": self.end_date,
+                    "locale": None,
                 },
                 "args": [self.facility.id],
                 "extra_metadata": {