Prevent leading and trailing spaces in translation values (#126427)

* Prevent leading and trailing spaces in translation values

* Adjust components

* Tests
This commit is contained in:
epenet 2024-09-22 16:01:08 +02:00 committed by GitHub
parent 90957dfedb
commit 7c5dc29981
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 14 additions and 12 deletions

View File

@ -275,7 +275,7 @@
"name": "Relative self consumption" "name": "Relative self consumption"
}, },
"capacity_maximum": { "capacity_maximum": {
"name": "Maximum capacity " "name": "Maximum capacity"
}, },
"capacity_designed": { "capacity_designed": {
"name": "Designed capacity" "name": "Designed capacity"

View File

@ -21,7 +21,7 @@
"data": { "data": {
"device_name": "Device Name" "device_name": "Device Name"
}, },
"description": "Enter your Hive configuration ", "description": "Enter your Hive configuration",
"title": "Hive Configuration." "title": "Hive Configuration."
}, },
"reauth": { "reauth": {

View File

@ -55,7 +55,7 @@
"name": "Cutting height" "name": "Cutting height"
}, },
"my_lawn_cutting_height": { "my_lawn_cutting_height": {
"name": "My lawn cutting height " "name": "My lawn cutting height"
}, },
"work_area_cutting_height": { "work_area_cutting_height": {
"name": "{work_area} cutting height" "name": "{work_area} cutting height"

View File

@ -3,7 +3,7 @@
"step": { "step": {
"user": { "user": {
"title": "Setup madVR Envy", "title": "Setup madVR Envy",
"description": "Your device needs to be on in order to add the integation. ", "description": "Your device needs to be on in order to add the integation.",
"data": { "data": {
"host": "[%key:common::config_flow::data::host%]", "host": "[%key:common::config_flow::data::host%]",
"port": "[%key:common::config_flow::data::port%]" "port": "[%key:common::config_flow::data::port%]"
@ -15,7 +15,7 @@
}, },
"reconfigure": { "reconfigure": {
"title": "Reconfigure madVR Envy", "title": "Reconfigure madVR Envy",
"description": "Your device needs to be on in order to reconfigure the integation. ", "description": "Your device needs to be on in order to reconfigure the integation.",
"data": { "data": {
"host": "[%key:common::config_flow::data::host%]", "host": "[%key:common::config_flow::data::host%]",
"port": "[%key:common::config_flow::data::port%]" "port": "[%key:common::config_flow::data::port%]"

View File

@ -100,7 +100,7 @@
}, },
"avoid_subscription_roads": { "avoid_subscription_roads": {
"name": "[%key:component::waze_travel_time::options::step::init::data::avoid_subscription_roads%]", "name": "[%key:component::waze_travel_time::options::step::init::data::avoid_subscription_roads%]",
"description": "Whether to avoid subscription roads. " "description": "Whether to avoid subscription roads."
} }
} }
} }

View File

@ -131,11 +131,13 @@ def translation_value_validator(value: Any) -> str:
- prevents strings with single quoted placeholders - prevents strings with single quoted placeholders
- prevents combined translations - prevents combined translations
""" """
value = cv.string_with_no_html(value) string_value = cv.string_with_no_html(value)
value = string_no_single_quoted_placeholders(value) string_value = string_no_single_quoted_placeholders(string_value)
if RE_COMBINED_REFERENCE.search(value): if RE_COMBINED_REFERENCE.search(string_value):
raise vol.Invalid("the string should not contain combined translations") raise vol.Invalid("the string should not contain combined translations")
return str(value) if string_value != string_value.strip(" "):
raise vol.Invalid("the string should not contain leading or trailing spaces")
return string_value
def string_no_single_quoted_placeholders(value: str) -> str: def string_no_single_quoted_placeholders(value: str) -> str:

View File

@ -195,7 +195,7 @@
}), }),
'original_device_class': None, 'original_device_class': None,
'original_icon': None, 'original_icon': None,
'original_name': 'My lawn cutting height ', 'original_name': 'My lawn cutting height',
'platform': 'husqvarna_automower', 'platform': 'husqvarna_automower',
'previous_unique_id': None, 'previous_unique_id': None,
'supported_features': 0, 'supported_features': 0,
@ -207,7 +207,7 @@
# name: test_number_snapshot[number.test_mower_1_my_lawn_cutting_height-state] # name: test_number_snapshot[number.test_mower_1_my_lawn_cutting_height-state]
StateSnapshot({ StateSnapshot({
'attributes': ReadOnlyDict({ 'attributes': ReadOnlyDict({
'friendly_name': 'Test Mower 1 My lawn cutting height ', 'friendly_name': 'Test Mower 1 My lawn cutting height',
'max': 100.0, 'max': 100.0,
'min': 0.0, 'min': 0.0,
'mode': <NumberMode.AUTO: 'auto'>, 'mode': <NumberMode.AUTO: 'auto'>,