diff --git a/blog/2025-10-22-service-translation-placeholders.md b/blog/2025-10-22-service-translation-placeholders.md new file mode 100644 index 00000000000..42dadb8c2b8 --- /dev/null +++ b/blog/2025-10-22-service-translation-placeholders.md @@ -0,0 +1,11 @@ +--- +author: Jan Bouwhuis +authorURL: https://github.com/jbouwh +authorImageURL: https://avatars.githubusercontent.com/u/7188918?s=96&v=4 +title: Introducing description placeholders for service action translations +--- +It is now possible to use translation placeholders for (custom) service actions. + +The [service action example](/docs/core/integration-quality-scale/rules/action-setup?_highlight=hass.services.async_register#example-implementation) now shows how to supply the available description placeholders during the registration of the service action. + +URLs that are part of the service transaction should be moved out of the service descriptions and translation strings using the description placeholders. diff --git a/docs/core/integration-quality-scale/rules/action-setup.md b/docs/core/integration-quality-scale/rules/action-setup.md index 0d92d60e4ef..f0d5111d66b 100644 --- a/docs/core/integration-quality-scale/rules/action-setup.md +++ b/docs/core/integration-quality-scale/rules/action-setup.md @@ -22,9 +22,10 @@ The example below is a snippet where the service action is registered in the `as In this example, the service call requires a configuration entry id as parameter. This is used to first fetch the configuration entry, and then check if it is loaded. If the configuration entry does not exist or the configuration entry that we found is not loaded, we raise a relevant error which is shown to the user. +Optional description placeholders can be supplied. `__init__py`: -```python {13-19} showLineNumbers +```python {13-20} showLineNumbers async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up my integration.""" @@ -43,6 +44,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: async_get_schedule, schema=SERVICE_GET_SCHEDULE_SCHEMA, supports_response=SupportsResponse.ONLY, + description_placeholders={"example_url": "https://schedule.example.com"} ) ``` diff --git a/docs/dev_101_services.md b/docs/dev_101_services.md index f491e37d77d..8277ec973b0 100644 --- a/docs/dev_101_services.md +++ b/docs/dev_101_services.md @@ -143,7 +143,18 @@ set_speed: ``` :::info -The name and description of the service actions are set in our [translations](/docs/internationalization/core#services) and not in the service action description. Each service action and service action field must have a matching translation defined. +The name and description of the service actions are set in our [translations](/docs/internationalization/core#services) and not in the service action description. Each service action and service action field must have a matching translation defined. Description placeholders can be used to keep out elements like URLs. + +```python +... + hass.services.async_register( + DOMAIN, + "hello",handle_hello, + description_placeholders={"docs_url": "https://example.com/hello_world"}, + ) +... +``` + ::: ### Grouping of service action fields diff --git a/docs/internationalization/core.md b/docs/internationalization/core.md index f8e1dabdc45..d747014cdbe 100644 --- a/docs/internationalization/core.md +++ b/docs/internationalization/core.md @@ -183,6 +183,8 @@ each collapsible section of fields. Note that also the translations for `name` and `description` of fields which are displayed in a collapsible section should be under the `fields` key. +Any description placeholders should be set be when the [service action is registered](/docs/dev_101_services/#service-action-description-example). + ```json { "selector": { @@ -198,7 +200,7 @@ are displayed in a collapsible section should be under the `fields` key. "services": { "set_speed": { "name": "Set speed", - "description": "Sets fan speed.", + "description": "Sets fan speed. [Learn more.]({docs_url})", "fields": { "speed": { "name": "Speed",