Fix translation merging for custom components without translations (#35032)
parent
9436645648
commit
b3201523aa
|
@ -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)
|
||||
|
||||
|
|
|
@ -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") == {}
|
||||
|
|
Loading…
Reference in New Issue