1
mirror of https://github.com/home-assistant/core synced 2024-10-07 10:13:38 +02:00

Fix translation merging for custom components without translations (#35032)

This commit is contained in:
Paulus Schoutsen 2020-05-01 11:34:09 -07:00 committed by GitHub
parent 9436645648
commit b3201523aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View File

@ -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)

View File

@ -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") == {}