1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Ensure translations for other integrations can be loaded if one integration fails (#110748)

* load failure

* merge
This commit is contained in:
J. Nick Koston
2024-02-17 20:01:36 -06:00
committed by GitHub
parent 0a01161cdd
commit 9bc130c131
2 changed files with 42 additions and 7 deletions

View File

@@ -114,7 +114,7 @@ def _merge_resources(
# We are going to merge the translations for the custom device classes into
# the translations of sensor.
new_value = translation_strings[component].get(category)
new_value = translation_strings.get(component, {}).get(category)
if new_value is None:
continue
@@ -135,17 +135,17 @@ def _merge_resources(
def build_resources(
translation_strings: dict[str, dict[str, Any]],
translation_strings: dict[str, dict[str, dict[str, Any] | str]],
components: set[str],
category: str,
) -> dict[str, dict[str, Any] | str]:
"""Build the resources response for the given components."""
# Build response
return {
component: translation_strings[component][category]
component: category_strings
for component in components
if category in translation_strings[component]
and translation_strings[component][category] is not None
if (component_strings := translation_strings.get(component))
and (category_strings := component_strings.get(category))
}
@@ -161,7 +161,8 @@ async def _async_get_component_strings(
files_to_load = {}
for loaded in components:
domain = loaded.partition(".")[0]
integration = integrations[domain]
if not (integration := integrations.get(domain)):
continue
path = component_translation_path(loaded, language, integration)
# No translation available
@@ -273,7 +274,10 @@ class _TranslationCache:
ints_or_excs = await async_get_integrations(self.hass, domains)
for domain, int_or_exc in ints_or_excs.items():
if isinstance(int_or_exc, Exception):
raise int_or_exc
_LOGGER.warning(
"Failed to load integration for translation: %s", int_or_exc
)
continue
integrations[domain] = int_or_exc
for translation_strings in await asyncio.gather(