Fix translations download (#36770)
This commit is contained in:
parent
e7e2f4e786
commit
02bcdf5162
1 changed files with 22 additions and 21 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue