From 02bcdf5162ac058075990df62393bff17ba9aa1e Mon Sep 17 00:00:00 2001
From: Paulus Schoutsen <balloob@gmail.com>
Date: Sun, 14 Jun 2020 11:38:05 -0700
Subject: [PATCH] Fix translations download (#36770)

---
 script/translations/download.py | 43 +++++++++++++++++----------------
 1 file changed, 22 insertions(+), 21 deletions(-)

diff --git a/script/translations/download.py b/script/translations/download.py
index 8f17e057080..7fc4c3365cc 100755
--- a/script/translations/download.py
+++ b/script/translations/download.py
@@ -7,7 +7,7 @@ import re
 import subprocess
 from typing import Dict, List, Union
 
-from .const import CLI_2_DOCKER_IMAGE, CORE_PROJECT_ID
+from .const import CLI_2_DOCKER_IMAGE, CORE_PROJECT_ID, INTEGRATIONS_DIR
 from .error import ExitApp
 from .util import get_lokalise_token
 
@@ -74,23 +74,13 @@ def get_component_path(lang, component):
 
 def get_platform_path(lang, component, platform):
     """Get the platform translation path."""
-    if os.path.isdir(os.path.join("homeassistant", "components", component, platform)):
-        return os.path.join(
-            "homeassistant",
-            "components",
-            component,
-            platform,
-            "translations",
-            f"{lang}.json",
-        )
-    else:
-        return os.path.join(
-            "homeassistant",
-            "components",
-            component,
-            "translations",
-            f"{platform}.{lang}.json",
-        )
+    return os.path.join(
+        "homeassistant",
+        "components",
+        component,
+        "translations",
+        f"{platform}.{lang}.json",
+    )
 
 
 def get_component_translations(translations):
@@ -111,9 +101,12 @@ def save_language_translations(lang, translations):
             os.makedirs(os.path.dirname(path), exist_ok=True)
             save_json(path, base_translations)
 
-        for platform, platform_translations in component_translations.get(
-            "platform", {}
-        ).items():
+        if "platform" not in component_translations:
+            continue
+
+        for platform, platform_translations in component_translations[
+            "platform"
+        ].items():
             path = get_platform_path(lang, component, platform)
             os.makedirs(os.path.dirname(path), exist_ok=True)
             save_json(path, platform_translations)
@@ -127,12 +120,20 @@ def write_integration_translations():
         save_language_translations(lang, translations)
 
 
+def delete_old_translations():
+    """Delete old translations."""
+    for fil in INTEGRATIONS_DIR.glob("*/translations/*"):
+        fil.unlink()
+
+
 def run():
     """Run the script."""
     DOWNLOAD_DIR.mkdir(parents=True, exist_ok=True)
 
     run_download_docker()
 
+    delete_old_translations()
+
     write_integration_translations()
 
     return 0
-- 
GitLab