Improve error messages from translation script (#102098)

Co-authored-by: Robert Resch <robert@resch.dev>
This commit is contained in:
Erik Montnemery
2023-10-22 23:45:27 +02:00
committed by GitHub
parent bc45de627a
commit 164872e1af
8 changed files with 59 additions and 24 deletions

View File

@ -6,6 +6,7 @@ import re
from .const import CORE_PROJECT_ID, FRONTEND_PROJECT_ID, INTEGRATIONS_DIR
from .lokalise import get_api
from .util import load_json_from_path
FRONTEND_REPO = pathlib.Path("../frontend/")
@ -164,7 +165,7 @@ def find_and_rename_keys():
if not strings_file.is_file():
continue
strings = json.loads(strings_file.read_text())
strings = load_json_from_path(strings_file)
if "title" in strings.get("config", {}):
from_key = f"component::{integration.name}::config::title"
@ -194,12 +195,12 @@ def interactive_update():
if not strings_file.is_file():
continue
strings = json.loads(strings_file.read_text())
strings = load_json_from_path(strings_file)
if "title" not in strings:
continue
manifest = json.loads((integration / "manifest.json").read_text())
manifest = load_json_from_path(integration / "manifest.json")
print("Processing", manifest["name"])
print("Translation title", strings["title"])
@ -247,9 +248,8 @@ def find_frontend_states():
Source key -> target key
Add key to integrations strings.json
"""
frontend_states = json.loads(
(FRONTEND_REPO / "src/translations/en.json").read_text()
)["state"]
path = FRONTEND_REPO / "src/translations/en.json"
frontend_states = load_json_from_path(path)["state"]
# domain => state object
to_write = {}
@ -307,7 +307,7 @@ def find_frontend_states():
for domain, state in to_write.items():
strings = INTEGRATIONS_DIR / domain / "strings.json"
if strings.is_file():
content = json.loads(strings.read_text())
content = load_json_from_path(strings)
else:
content = {}
@ -326,7 +326,7 @@ def find_frontend_states():
def apply_data_references(to_migrate):
"""Apply references."""
for strings_file in INTEGRATIONS_DIR.glob("*/strings.json"):
strings = json.loads(strings_file.read_text())
strings = load_json_from_path(strings_file)
steps = strings.get("config", {}).get("step")
if not steps: