Repository: learningequality/kolibri

Issue:
Backend strings not in the expected folder when running 'make i18n-upload' command
## Observed behavior

Branch: `release-v0.15.x`
Running `make i18n-upload...` command extracts all front- and back-end strings, but the `django.po` file is not being uploaded to Crowdin. 
cc @rtibbles 

## Errors and logs
…

## Expected behavior
`django.po` should be available on Crowdin for translation

## User-facing consequences
…

## Steps to reproduce
…

## Context
 * Kolibri version `release-v0.15.x`
 * Operating system -
 * Browser -




Discussion:

Resolving patch:
diff --git a/packages/kolibri-tools/lib/i18n/crowdin.py b/packages/kolibri-tools/lib/i18n/crowdin.py
--- a/packages/kolibri-tools/lib/i18n/crowdin.py
+++ b/packages/kolibri-tools/lib/i18n/crowdin.py
@@ -11,6 +11,7 @@
 import os
 import shutil
 import sys
+import tempfile
 import zipfile
 
 import click
@@ -285,13 +286,6 @@ def upload_translations(branch, project, key, login, locale_data_folder):
 """
 
 
-def _wipe_translations(locale_path):
-    for file_name in os.listdir(locale_path):
-        target = os.path.join(locale_path, file_name)
-        if file_name != "en" and os.path.isdir(target):
-            shutil.rmtree(target)
-
-
 @click.command(cls=CrowdinCommand)
 @branch_argument
 @locale_data_folder_option
@@ -301,32 +295,34 @@ def download_translations(branch, project, key, login, locale_data_folder):
     """
     logging.info("Crowdin: downloading '{}'...".format(branch))
 
-    # delete previous files
-    _wipe_translations(locale_data_folder)
-
     DOWNLOAD_URL = CROWDIN_API_URL.format(
         proj=project,
         key=key,
         username=login,
         cmd="download/all.zip",
-        params="&branch={branch}&language={language}",
+        params="&branch={branch}".format(branch=branch),
     )
 
-    csv_dir_path = utils.local_locale_csv_path(locale_data_folder)
+    zip_dir = tempfile.mkdtemp()
+
+    r = requests.get(DOWNLOAD_URL)
+    r.raise_for_status()
+    z = zipfile.ZipFile(io.BytesIO(r.content))
+    z.extractall(zip_dir)
+
     for lang_object in utils.available_languages(include_in_context=True):
         code = lang_object[utils.KEY_CROWDIN_CODE]
-        url = DOWNLOAD_URL.format(language=code, branch=branch)
-        r = requests.get(url)
-        r.raise_for_status()
-        z = zipfile.ZipFile(io.BytesIO(r.content))
-        logging.info("\tExtracting {} to {}".format(code, csv_dir_path))
-        z.extractall(csv_dir_path)
-        csv_locale_dir_path = os.path.join(csv_dir_path, lang_object["crowdin_code"])
-        po_file = os.path.join(csv_locale_dir_path, "django.po")
-        if os.path.exists(po_file):
-            shutil.move(
-                po_file, utils.local_locale_path(lang_object, locale_data_folder)
-            )
+        locale_dir_path = utils.local_locale_path(lang_object, locale_data_folder)
+        logging.info("\tExtracting {} to {}".format(code, locale_dir_path))
+        MESSAGES = os.path.join(zip_dir, code)
+        if os.path.exists(MESSAGES):
+            for msg_file in os.listdir(MESSAGES):
+                shutil.move(
+                    os.path.join(MESSAGES, msg_file),
+                    os.path.join(locale_dir_path, msg_file),
+                )
+
+    shutil.rmtree(zip_dir, ignore_errors=True)
 
     logging.info("Crowdin: download succeeded!")
 
@@ -386,7 +382,7 @@ def upload_glossary(project, key, login, locale_data_folder):
 
 def _source_upload_ref(file_name, locale_data_folder):
     file_pointer = open(
-        os.path.join(utils.local_locale_csv_source_path(locale_data_folder), file_name),
+        os.path.join(utils.local_locale_source_path(locale_data_folder), file_name),
         "rb",
     )
     return ("files[{0}]".format(file_name), file_pointer)
@@ -437,9 +433,7 @@ def upload_sources(branch, project, key, login, locale_data_folder):
 
     source_files = set(
         file_name
-        for file_name in os.listdir(
-            utils.local_locale_csv_source_path(locale_data_folder)
-        )
+        for file_name in os.listdir(utils.local_locale_source_path(locale_data_folder))
         if is_string_file(file_name)
     )
 
diff --git a/packages/kolibri-tools/lib/i18n/utils.py b/packages/kolibri-tools/lib/i18n/utils.py
--- a/packages/kolibri-tools/lib/i18n/utils.py
+++ b/packages/kolibri-tools/lib/i18n/utils.py
@@ -93,20 +93,8 @@ def local_locale_path(lang_object, locale_data_folder):
 
 # Defines where we find the extracted messages
 @memoize
-def local_locale_csv_source_path(locale_data_folder):
-    csv_path = os.path.abspath(os.path.join(locale_data_folder, "CSV_FILES", "en"))
-    if not os.path.exists(csv_path):
-        os.makedirs(csv_path)
-    return csv_path
-
-
-# Defines where we'll find the downloaded CSV files from Crowdin (non english files)
-@memoize
-def local_locale_csv_path(locale_data_folder):
-    csv_path = os.path.abspath(os.path.join(locale_data_folder, "CSV_FILES"))
-    if not os.path.exists(csv_path):
-        os.makedirs(csv_path)
-    return csv_path
+def local_locale_source_path(locale_data_folder):
+    return local_locale_path({KEY_INTL_CODE: "en"}, locale_data_folder)
 
 
 def json_dump_formatted(data, file_path, file_name):


Test patch: