1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Limit legacy state translations to custom components (#112295)

* Limit legacy state translations to custom components

We were trying to load **thousands** of `*.light.json`, `*.switch.json` files at run time that did not exist.

There have been replaced with entity translations: https://github.com/home-assistant/developers.home-assistant/pull/1557 https://github.com/home-assistant/core/pull/82701

https://github.com/home-assistant/core/pull/112023 will completely remove them, but
for now we will only load them for custom components to reduce the number
of files having to be examined

* reduce

* reduce

* reduce

* reduce

* comment

* coverage

* try to remove empty dict in loaded_translations fallback when missing
This commit is contained in:
J. Nick Koston
2024-03-05 12:27:45 -10:00
committed by GitHub
parent d34e2c1f12
commit fbabbc8f92
6 changed files with 106 additions and 26 deletions

View File

@@ -165,20 +165,21 @@ async def _async_get_component_strings(
for language in languages:
files_to_load: dict[str, str] = {}
files_to_load_by_language[language] = files_to_load
loaded_translations: dict[str, Any] = {}
translations_by_language[language] = loaded_translations
translations_by_language[language] = {}
for loaded in components:
domain = loaded.partition(".")[0]
domain, _, platform = loaded.partition(".")
if not (integration := integrations.get(domain)):
continue
path = component_translation_path(loaded, language, integration)
# No translation available
if path is None:
loaded_translations[loaded] = {}
else:
if platform and integration.is_built_in:
# Legacy state translations are no longer used for built-in integrations
# and we avoid trying to load them. This is a temporary measure to allow
# them to keep working for custom integrations until we can fully remove
# them.
continue
if path := component_translation_path(loaded, language, integration):
files_to_load[loaded] = path
if not files_to_load: