Use translation placeholders in Swiss public transport (#106416)

This commit is contained in:
Joost Lekkerkerker 2023-12-27 09:01:53 +01:00 committed by GitHub
parent 65e8bbacc9
commit f92e732f27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 9 deletions

View File

@ -15,7 +15,7 @@ from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from .const import CONF_DESTINATION, CONF_START, DOMAIN from .const import CONF_DESTINATION, CONF_START, DOMAIN, PLACEHOLDERS
DATA_SCHEMA = vol.Schema( DATA_SCHEMA = vol.Schema(
{ {
@ -65,7 +65,10 @@ class SwissPublicTransportConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
) )
return self.async_show_form( return self.async_show_form(
step_id="user", data_schema=DATA_SCHEMA, errors=errors step_id="user",
data_schema=DATA_SCHEMA,
errors=errors,
description_placeholders=PLACEHOLDERS,
) )
async def async_step_import(self, import_input: dict[str, Any]) -> FlowResult: async def async_step_import(self, import_input: dict[str, Any]) -> FlowResult:

View File

@ -7,3 +7,9 @@ CONF_DESTINATION = "to"
CONF_START = "from" CONF_START = "from"
DEFAULT_NAME = "Next Destination" DEFAULT_NAME = "Next Destination"
PLACEHOLDERS = {
"stationboard_url": "http://transport.opendata.ch/examples/stationboard.html",
"opendata_url": "http://transport.opendata.ch",
}

View File

@ -22,7 +22,7 @@ from homeassistant.helpers.issue_registry import IssueSeverity, async_create_iss
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
from .const import CONF_DESTINATION, CONF_START, DEFAULT_NAME, DOMAIN from .const import CONF_DESTINATION, CONF_START, DEFAULT_NAME, DOMAIN, PLACEHOLDERS
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -104,11 +104,12 @@ async def async_setup_platform(
issue_domain=DOMAIN, issue_domain=DOMAIN,
severity=IssueSeverity.WARNING, severity=IssueSeverity.WARNING,
translation_key=f"deprecated_yaml_import_issue_${result['reason']}", translation_key=f"deprecated_yaml_import_issue_${result['reason']}",
translation_placeholders=PLACEHOLDERS,
) )
class SwissPublicTransportSensor(SensorEntity): class SwissPublicTransportSensor(SensorEntity):
"""Implementation of an Swiss public transport sensor.""" """Implementation of a Swiss public transport sensor."""
_attr_attribution = "Data provided by transport.opendata.ch" _attr_attribution = "Data provided by transport.opendata.ch"
_attr_icon = "mdi:bus" _attr_icon = "mdi:bus"

View File

@ -2,13 +2,13 @@
"config": { "config": {
"error": { "error": {
"cannot_connect": "Cannot connect to server", "cannot_connect": "Cannot connect to server",
"bad_config": "Request failed due to bad config: Check at [stationboard](http://transport.opendata.ch/examples/stationboard.html) if your station names are valid", "bad_config": "Request failed due to bad config: Check at [stationboard]({stationboard_url}) if your station names are valid",
"unknown": "An unknown error was raised by python-opendata-transport" "unknown": "An unknown error was raised by python-opendata-transport"
}, },
"abort": { "abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]", "already_configured": "[%key:common::config_flow::abort::already_configured_service%]",
"cannot_connect": "Cannot connect to server", "cannot_connect": "Cannot connect to server",
"bad_config": "Request failed due to bad config: Check at [stationboard](http://transport.opendata.ch/examples/stationboard.html) if your station names are valid", "bad_config": "Request failed due to bad config: Check the [stationboard]({stationboard_url}) for valid stations.",
"unknown": "An unknown error was raised by python-opendata-transport" "unknown": "An unknown error was raised by python-opendata-transport"
}, },
"step": { "step": {
@ -17,7 +17,7 @@
"from": "Start station", "from": "Start station",
"to": "End station" "to": "End station"
}, },
"description": "Provide start and end station for your connection\n\nCheck here for valid stations: [stationboard](http://transport.opendata.ch/examples/stationboard.html)", "description": "Provide start and end station for your connection\n\nCheck the [stationboard]({stationboard_url}) for valid stations.",
"title": "Swiss Public Transport" "title": "Swiss Public Transport"
} }
} }
@ -25,11 +25,11 @@
"issues": { "issues": {
"deprecated_yaml_import_issue_cannot_connect": { "deprecated_yaml_import_issue_cannot_connect": {
"title": "The swiss public transport YAML configuration import cannot connect to server", "title": "The swiss public transport YAML configuration import cannot connect to server",
"description": "Configuring swiss public transport using YAML is being removed but there was an connection error importing your YAML configuration.\n\nMake sure your home assistant can reach the [opendata server](http://transport.opendata.ch). In case the server is down, try again later." "description": "Configuring swiss public transport using YAML is being removed but there was an connection error importing your YAML configuration.\n\nMake sure your home assistant can reach the [opendata server]({opendata_url}). In case the server is down, try again later."
}, },
"deprecated_yaml_import_issue_bad_config": { "deprecated_yaml_import_issue_bad_config": {
"title": "The swiss public transport YAML configuration import request failed due to bad config", "title": "The swiss public transport YAML configuration import request failed due to bad config",
"description": "Configuring swiss public transport using YAML is being removed but there was bad config imported in your YAML configuration..\n\nCheck here for valid stations: [stationboard](http://transport.opendata.ch/examples/stationboard.html)" "description": "Configuring swiss public transport using YAML is being removed but there was bad config imported in your YAML configuration.\n\nCheck the [stationboard]({stationboard_url}) for valid stations."
}, },
"deprecated_yaml_import_issue_unknown": { "deprecated_yaml_import_issue_unknown": {
"title": "The swiss public transport YAML configuration import failed with unknown error raised by python-opendata-transport", "title": "The swiss public transport YAML configuration import failed with unknown error raised by python-opendata-transport",