-
-
Notifications
You must be signed in to change notification settings - Fork 36.3k
Make add entry translatable #159901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Make add entry translatable #159901
Conversation
|
Hey there @frenck, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enables integrations to customize the "Add entry" button text in the frontend. Instead of showing generic text like "Add service" or "Add hub", integrations can now specify more contextually appropriate text like "Add account" for account-based services like Spotify.
Key changes:
- Extended the translation schema to support optional
initiate_flowconfiguration for regular config flows (previously only available for subentry flows) - Added a common translation string for "account" in the global strings.json
- Updated Spotify integration to use "Add account" instead of the default button text
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
script/hassfest/translations.py |
Added schema validation for optional initiate_flow in regular config flows with required "user" key |
homeassistant/strings.json |
Added common translation string "account" under config_flow.initiate_flow |
homeassistant/components/spotify/strings.json |
Configured Spotify to use "Add account" button text by referencing the common translation |
| "create_entry": { | ||
| "default": "Successfully authenticated with Spotify." | ||
| }, | ||
| "initiate_flow": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initiate_flow is too generic, we also have options flow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, so for the subentries we have initiate_flow, this just reuses it
https://github.com/home-assistant/core/blob/dev/homeassistant/components/google_weather/strings.json#L48-L50
| "default": "Successfully authenticated with Spotify." | ||
| }, | ||
| "initiate_flow": { | ||
| "user": "[%key:common::config_flow::initiate_flow::account%]" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's only user facing strings, any reason to have a dictionary underneath?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just because reusing the existing logic, no other reason.
| schema[vol.Optional("initiate_flow")] = { | ||
| vol.Required("user"): translation_value_validator, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish we could enforce the use of references because there probably won't be more than like 5-10 unique strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-use is always encouraged (and generally works), but locking it down I'm not a fan of.
Proposed change
So some integrations are considered a service or hub and the frontend will show "Add service" or "Add hub". While in reality, for example in the case of Spotify, it's not a service they add, but rather an account, so this PR allows integrations to overwrite this button's text, so you can change it to "Add account" to make it more user friendly :)
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: