Translating dynamic fields in integration Config flows form

Hi everyone,

TLDR: Have you run into problems translating dynamic fields when building config flow forms for a Home Assistant integration? If so, how did you deal with it? I’d love to hear your experiences and ideas for solutions to address this. Here’s my proposal.

I’m reaching out to the community, especially integration developers, about a limitation in Home Assistant’s config flow form implementation regarding translations for dynamic fields.

The problem

In the Data Entry Flow forms (Config / Options / Subentry flows), it is currently not possible to translate dynamic fields or sections (for which the keys are only known at runtime) because of how the form data_schema keys are directly used to map the translations from the strings.json.

Let me give you a concrete example from my own integration work. I was building a config flow where the form fields are generated dynamically: I needed to show a section for each device the user has with a title depending on the device name. Here is what it should look like with 2 devices for example:

But with the current implementation, I can’t translate the fields inside the sections and do any interpolation for the sections title.

What I’m proposing

I’ve put together a GitHub architecture discussion to address this: basically, let us map dynamic field keys to static translation keys using a translation_field_mappings dictionary with placeholders used for interpolation. This should make it possible to get proper translations for those dynamic fields.

Looking for your experiences and thoughts

  • Have you run into this problem before? What was your use case?
  • Did you find a workaround? How did you handle it?
  • Does my idea sound helpful, or is there a better way to tackle this?
  • Any gotchas or concerns I might not have thought of?

Would love to hear how others have handled this or if you’ve just been annoyed by it too! If you’ve got suggestions for a better approach, I’m all ears.

Thanks for reading!

I ran into this problem, but rather than displaying multiple sections on the same config step, I’m just using the same config step multiple times.

So first step the user specifies a number of rooms, then it calls a room config step where the user can enter all the necessary info for the room, then each time this step is called the user_data is appended to a list in the config. Once the list is equal in length to the number specified then you know you’re done.

I don’t know that this will solve every use case but it solved mine.

For your use case you could say how many zones on the first config flow step, then add another step where the user selects the zone, and specifies the exit/entry entitites.