From cccfc3a15241fa51855c07255432349257bc2f71 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Tue, 12 May 2026 07:45:11 -0500 Subject: [PATCH] fix nested translation extraction for Optional dict and list fields --- generate_config_translations.py | 52 ++++++++++++++++------- web/public/locales/en/config/cameras.json | 6 ++- web/public/locales/en/config/global.json | 6 ++- 3 files changed, 47 insertions(+), 17 deletions(-) diff --git a/generate_config_translations.py b/generate_config_translations.py index 032edb2327..9bc830855d 100644 --- a/generate_config_translations.py +++ b/generate_config_translations.py @@ -150,29 +150,51 @@ def extract_translations_from_schema( # Handle anyOf cases elif "anyOf" in field_schema: for item in field_schema["anyOf"]: + nested = None + if item.get("type") == "null": + continue if "properties" in item: nested = extract_translations_from_schema(item, defs=defs) + elif "$ref" in item: + ref_path = item["$ref"] + if ref_path.startswith("#/$defs/"): + ref_name = ref_path.split("/")[-1] + if ref_name in defs: + nested = extract_translations_from_schema( + defs[ref_name], defs=defs + ) + elif ( + "additionalProperties" in item + and isinstance(item["additionalProperties"], dict) + and "$ref" in item["additionalProperties"] + ): + ref_path = item["additionalProperties"]["$ref"] + if ref_path.startswith("#/$defs/"): + ref_name = ref_path.split("/")[-1] + if ref_name in defs: + nested = extract_translations_from_schema( + defs[ref_name], defs=defs + ) + elif ( + "items" in item + and isinstance(item["items"], dict) + and ("$ref" in item["items"]) + ): + ref_path = item["items"]["$ref"] + if ref_path.startswith("#/$defs/"): + ref_name = ref_path.split("/")[-1] + if ref_name in defs: + nested = extract_translations_from_schema( + defs[ref_name], defs=defs + ) + + if nested: nested_without_root = { k: v for k, v in nested.items() if k not in ("label", "description") } field_translations.update(nested_without_root) - elif "$ref" in item: - ref_path = item["$ref"] - if ref_path.startswith("#/$defs/"): - ref_name = ref_path.split("/")[-1] - if ref_name in defs: - ref_schema = defs[ref_name] - nested = extract_translations_from_schema( - ref_schema, defs=defs - ) - nested_without_root = { - k: v - for k, v in nested.items() - if k not in ("label", "description") - } - field_translations.update(nested_without_root) if field_translations: translations[field_name] = field_translations diff --git a/web/public/locales/en/config/cameras.json b/web/public/locales/en/config/cameras.json index 65f9815753..4f2c0ea01e 100644 --- a/web/public/locales/en/config/cameras.json +++ b/web/public/locales/en/config/cameras.json @@ -33,7 +33,11 @@ }, "filters": { "label": "Audio filters", - "description": "Per-audio-type filter settings such as confidence thresholds used to reduce false positives." + "description": "Per-audio-type filter settings such as confidence thresholds used to reduce false positives.", + "threshold": { + "label": "Minimum audio confidence", + "description": "Minimum confidence threshold for the audio event to be counted." + } }, "enabled_in_config": { "label": "Original audio state", diff --git a/web/public/locales/en/config/global.json b/web/public/locales/en/config/global.json index 8efecd0ced..61f0e41cc0 100644 --- a/web/public/locales/en/config/global.json +++ b/web/public/locales/en/config/global.json @@ -559,7 +559,11 @@ }, "filters": { "label": "Audio filters", - "description": "Per-audio-type filter settings such as confidence thresholds used to reduce false positives." + "description": "Per-audio-type filter settings such as confidence thresholds used to reduce false positives.", + "threshold": { + "label": "Minimum audio confidence", + "description": "Minimum confidence threshold for the audio event to be counted." + } }, "enabled_in_config": { "label": "Original audio state",