diff --git a/homeassistant/helpers/translation.py b/homeassistant/helpers/translation.py index 0c59035fc76..7ccbea3653d 100644 --- a/homeassistant/helpers/translation.py +++ b/homeassistant/helpers/translation.py @@ -143,25 +143,18 @@ def _build_resources( } -async def async_get_component_strings( - hass: HomeAssistant, language: str, components: set[str] +async def _async_get_component_strings( + hass: HomeAssistant, + language: str, + components: set[str], + integrations: dict[str, Integration], ) -> dict[str, Any]: """Load translations.""" - domains = list({loaded.rpartition(".")[-1] for loaded in components}) - - integrations: dict[str, Integration] = {} - ints_or_excs = await async_get_integrations(hass, domains) - for domain, int_or_exc in ints_or_excs.items(): - if isinstance(int_or_exc, Exception): - raise int_or_exc - integrations[domain] = int_or_exc translations: dict[str, Any] = {} - # Determine paths of missing components/platforms files_to_load = {} for loaded in components: - parts = loaded.split(".") - domain = parts[-1] + domain = loaded.rpartition(".")[-1] integration = integrations[domain] path = component_translation_path(loaded, language, integration) @@ -228,9 +221,18 @@ class _TranslationCache: ) # Fetch the English resources, as a fallback for missing keys languages = [LOCALE_EN] if language == LOCALE_EN else [LOCALE_EN, language] + + integrations: dict[str, Integration] = {} + domains = list({loaded.rpartition(".")[-1] for loaded in components}) + 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 + integrations[domain] = int_or_exc + for translation_strings in await asyncio.gather( *( - async_get_component_strings(self.hass, lang, components) + _async_get_component_strings(self.hass, lang, components, integrations) for lang in languages ) ):