Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions homeassistant/components/onboarding/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,27 @@ async def post(self, request: web.Request, data: dict[str, str]) -> web.Response
if await async_wait_component(hass, "person"):
await person.async_create_person(hass, data["name"], user_id=user.id)

# Create default areas using the users supplied language.
translations = await async_get_translations(
hass, data["language"], "area", {DOMAIN}
# Create default areas using the user-supplied language,
# falling back to English for any missing keys.
language = data["language"]
english_translations = await async_get_translations(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion we should do this transparent in async_get_translations.
async_get_translations should always return all the keys. If a translation is missing in the given language we include the english one. So we don't need to implement the manual fallback on each call and fix the issues for all occurrences.

@frenck What do you think?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how would we know that not all keys are there?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Essentially load english, overwrite with the lanbguage in the same structure, but deep merging that isn't really efficient I would say.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm so what the crap is going south here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's reported against the dev branch. Maybe they didn't generate translations? They are auto-generated when you run script/setup, but this person might not have run that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closing I can only conclude the same.

hass, "en", "area", {DOMAIN}
)
if language == "en":
translations = english_translations
else:
translations = await async_get_translations(
hass, language, "area", {DOMAIN}
)

area_registry = ar.async_get(hass)

for area in DEFAULT_AREAS:
name = translations[f"component.onboarding.area.{area.key}"]
translation_key = f"component.onboarding.area.{area.key}"
name = translations.get(
translation_key,
english_translations.get(translation_key, area.key),
)
Comment thread
frenck marked this conversation as resolved.
# Guard because area might have been created by an automatically
# set up integration.
if not area_registry.async_get_area_by_name(name):
Expand Down