diff --git a/homeassistant/helpers/translation.py b/homeassistant/helpers/translation.py index abf39972186..d0fac953ac1 100644 --- a/homeassistant/helpers/translation.py +++ b/homeassistant/helpers/translation.py @@ -210,6 +210,9 @@ async def async_get_component_strings( else: files_to_load[loaded] = path + if not files_to_load: + return translations + # Load files load_translations_job = hass.async_add_executor_job( load_translations_files, files_to_load @@ -218,12 +221,12 @@ async def async_get_component_strings( loaded_translations = await load_translations_job # Translations that miss "title" will get integration put in. - for loaded, translations in loaded_translations.items(): + for loaded, loaded_translation in loaded_translations.items(): if "." in loaded: continue - if "title" not in translations: - translations["title"] = integrations[loaded].name + if "title" not in loaded_translation: + loaded_translation["title"] = integrations[loaded].name translations.update(loaded_translations) diff --git a/tests/helpers/test_translation.py b/tests/helpers/test_translation.py index 8596b9dd7f3..77e55a1d6ed 100644 --- a/tests/helpers/test_translation.py +++ b/tests/helpers/test_translation.py @@ -267,3 +267,11 @@ async def test_caching(hass): await translation.async_get_translations(hass, "en", "state") assert len(mock_merge.mock_calls) == 2 + + +async def test_custom_component_translations(hass): + """Test getting translation from custom components.""" + hass.config.components.add("test_standalone") + hass.config.components.add("test_embedded") + hass.config.components.add("test_package") + assert await translation.async_get_translations(hass, "en", "state") == {}