mirror of https://github.com/home-assistant/core
Fix translations download (#36770)
This commit is contained in:
parent
e7e2f4e786
commit
02bcdf5162
|
@ -7,7 +7,7 @@ import re
|
||||||
import subprocess
|
import subprocess
|
||||||
from typing import Dict, List, Union
|
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 .error import ExitApp
|
||||||
from .util import get_lokalise_token
|
from .util import get_lokalise_token
|
||||||
|
|
||||||
|
@ -74,23 +74,13 @@ def get_component_path(lang, component):
|
||||||
|
|
||||||
def get_platform_path(lang, component, platform):
|
def get_platform_path(lang, component, platform):
|
||||||
"""Get the platform translation path."""
|
"""Get the platform translation path."""
|
||||||
if os.path.isdir(os.path.join("homeassistant", "components", component, platform)):
|
return os.path.join(
|
||||||
return os.path.join(
|
"homeassistant",
|
||||||
"homeassistant",
|
"components",
|
||||||
"components",
|
component,
|
||||||
component,
|
"translations",
|
||||||
platform,
|
f"{platform}.{lang}.json",
|
||||||
"translations",
|
)
|
||||||
f"{lang}.json",
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
return os.path.join(
|
|
||||||
"homeassistant",
|
|
||||||
"components",
|
|
||||||
component,
|
|
||||||
"translations",
|
|
||||||
f"{platform}.{lang}.json",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def get_component_translations(translations):
|
def get_component_translations(translations):
|
||||||
|
@ -111,9 +101,12 @@ def save_language_translations(lang, translations):
|
||||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||||
save_json(path, base_translations)
|
save_json(path, base_translations)
|
||||||
|
|
||||||
for platform, platform_translations in component_translations.get(
|
if "platform" not in component_translations:
|
||||||
"platform", {}
|
continue
|
||||||
).items():
|
|
||||||
|
for platform, platform_translations in component_translations[
|
||||||
|
"platform"
|
||||||
|
].items():
|
||||||
path = get_platform_path(lang, component, platform)
|
path = get_platform_path(lang, component, platform)
|
||||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||||
save_json(path, platform_translations)
|
save_json(path, platform_translations)
|
||||||
|
@ -127,12 +120,20 @@ def write_integration_translations():
|
||||||
save_language_translations(lang, translations)
|
save_language_translations(lang, translations)
|
||||||
|
|
||||||
|
|
||||||
|
def delete_old_translations():
|
||||||
|
"""Delete old translations."""
|
||||||
|
for fil in INTEGRATIONS_DIR.glob("*/translations/*"):
|
||||||
|
fil.unlink()
|
||||||
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
"""Run the script."""
|
"""Run the script."""
|
||||||
DOWNLOAD_DIR.mkdir(parents=True, exist_ok=True)
|
DOWNLOAD_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
run_download_docker()
|
run_download_docker()
|
||||||
|
|
||||||
|
delete_old_translations()
|
||||||
|
|
||||||
write_integration_translations()
|
write_integration_translations()
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
Loading…
Reference in New Issue