mirror of
https://github.com/home-assistant/core.git
synced 2025-08-16 02:51:40 +02:00
Fix incorrect scope on checking files to load in translations (#112457)
discovered in https://github.com/home-assistant/core/pull/112295#discussion_r1513505710 We only checked if the last language had files to load instead of all of them. The checks for each language are the same because the only reason we would skip a language is a missing/broken integration or the integration is a single file. Both of these loop conditions are always the same reguardless of the language so the check worked
This commit is contained in:
@@ -162,13 +162,14 @@ async def _async_get_component_strings(
|
||||
translations_by_language: dict[str, dict[str, Any]] = {}
|
||||
# Determine paths of missing components/platforms
|
||||
files_to_load_by_language: dict[str, dict[str, str]] = {}
|
||||
has_files_to_load = False
|
||||
for language in languages:
|
||||
files_to_load: dict[str, str] = {}
|
||||
files_to_load_by_language[language] = files_to_load
|
||||
translations_by_language[language] = {}
|
||||
|
||||
for loaded in components:
|
||||
domain, _, platform = loaded.partition(".")
|
||||
for comp in components:
|
||||
domain, _, platform = comp.partition(".")
|
||||
if not (integration := integrations.get(domain)):
|
||||
continue
|
||||
|
||||
@@ -179,10 +180,11 @@ async def _async_get_component_strings(
|
||||
# them.
|
||||
continue
|
||||
|
||||
if path := component_translation_path(loaded, language, integration):
|
||||
files_to_load[loaded] = path
|
||||
if path := component_translation_path(comp, language, integration):
|
||||
files_to_load[comp] = path
|
||||
has_files_to_load = True
|
||||
|
||||
if not files_to_load:
|
||||
if not has_files_to_load:
|
||||
return translations_by_language
|
||||
|
||||
# Load files
|
||||
|
@@ -541,6 +541,37 @@ async def test_ensure_translations_still_load_if_one_integration_fails(
|
||||
assert translations == sensor_translations
|
||||
|
||||
|
||||
async def test_load_translations_all_integrations_broken(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Ensure we do not try to load translations again if the integration is broken."""
|
||||
hass.config.components.add("broken")
|
||||
hass.config.components.add("broken2")
|
||||
|
||||
with patch(
|
||||
"homeassistant.helpers.translation.async_get_integrations",
|
||||
return_value={
|
||||
"broken2": Exception("unhandled failure"),
|
||||
"broken": Exception("unhandled failure"),
|
||||
},
|
||||
):
|
||||
translations = await translation.async_get_translations(
|
||||
hass, "en", "entity_component", integrations={"broken", "broken2"}
|
||||
)
|
||||
assert "Failed to load integration for translation" in caplog.text
|
||||
assert "broken" in caplog.text
|
||||
assert "broken2" in caplog.text
|
||||
assert not translations
|
||||
caplog.clear()
|
||||
|
||||
translations = await translation.async_get_translations(
|
||||
hass, "en", "entity_component", integrations={"broken", "broken2"}
|
||||
)
|
||||
assert not translations
|
||||
# Ensure we do not try again
|
||||
assert "Failed to load integration for translation" not in caplog.text
|
||||
|
||||
|
||||
async def test_caching(hass: HomeAssistant) -> None:
|
||||
"""Test we cache data."""
|
||||
hass.config.components.add("sensor")
|
||||
|
Reference in New Issue
Block a user