mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +00:00
Add unit translations for github integration (#130538)
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
parent
3542bca13d
commit
4776865584
@ -37,7 +37,6 @@ SENSOR_DESCRIPTIONS: tuple[GitHubSensorEntityDescription, ...] = (
|
||||
GitHubSensorEntityDescription(
|
||||
key="discussions_count",
|
||||
translation_key="discussions_count",
|
||||
native_unit_of_measurement="Discussions",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
value_fn=lambda data: data["discussion"]["total"],
|
||||
@ -45,7 +44,6 @@ SENSOR_DESCRIPTIONS: tuple[GitHubSensorEntityDescription, ...] = (
|
||||
GitHubSensorEntityDescription(
|
||||
key="stargazers_count",
|
||||
translation_key="stargazers_count",
|
||||
native_unit_of_measurement="Stars",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
value_fn=lambda data: data["stargazers_count"],
|
||||
@ -53,7 +51,6 @@ SENSOR_DESCRIPTIONS: tuple[GitHubSensorEntityDescription, ...] = (
|
||||
GitHubSensorEntityDescription(
|
||||
key="subscribers_count",
|
||||
translation_key="subscribers_count",
|
||||
native_unit_of_measurement="Watchers",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
value_fn=lambda data: data["watchers"]["total"],
|
||||
@ -61,7 +58,6 @@ SENSOR_DESCRIPTIONS: tuple[GitHubSensorEntityDescription, ...] = (
|
||||
GitHubSensorEntityDescription(
|
||||
key="forks_count",
|
||||
translation_key="forks_count",
|
||||
native_unit_of_measurement="Forks",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
value_fn=lambda data: data["forks_count"],
|
||||
@ -69,7 +65,6 @@ SENSOR_DESCRIPTIONS: tuple[GitHubSensorEntityDescription, ...] = (
|
||||
GitHubSensorEntityDescription(
|
||||
key="issues_count",
|
||||
translation_key="issues_count",
|
||||
native_unit_of_measurement="Issues",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
value_fn=lambda data: data["issue"]["total"],
|
||||
@ -77,7 +72,6 @@ SENSOR_DESCRIPTIONS: tuple[GitHubSensorEntityDescription, ...] = (
|
||||
GitHubSensorEntityDescription(
|
||||
key="pulls_count",
|
||||
translation_key="pulls_count",
|
||||
native_unit_of_measurement="Pull Requests",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
value_fn=lambda data: data["pull_request"]["total"],
|
||||
|
@ -19,22 +19,28 @@
|
||||
"entity": {
|
||||
"sensor": {
|
||||
"discussions_count": {
|
||||
"name": "Discussions"
|
||||
"name": "Discussions",
|
||||
"unit_of_measurement": "discussions"
|
||||
},
|
||||
"stargazers_count": {
|
||||
"name": "Stars"
|
||||
"name": "Stars",
|
||||
"unit_of_measurement": "stars"
|
||||
},
|
||||
"subscribers_count": {
|
||||
"name": "Watchers"
|
||||
"name": "Watchers",
|
||||
"unit_of_measurement": "watchers"
|
||||
},
|
||||
"forks_count": {
|
||||
"name": "Forks"
|
||||
"name": "Forks",
|
||||
"unit_of_measurement": "forks"
|
||||
},
|
||||
"issues_count": {
|
||||
"name": "Issues"
|
||||
"name": "Issues",
|
||||
"unit_of_measurement": "issues"
|
||||
},
|
||||
"pulls_count": {
|
||||
"name": "Pull requests"
|
||||
"name": "Pull requests",
|
||||
"unit_of_measurement": "pull requests"
|
||||
},
|
||||
"latest_commit": {
|
||||
"name": "Latest commit"
|
||||
|
@ -368,6 +368,9 @@ def gen_strings_schema(config: Config, integration: Integration) -> vol.Schema:
|
||||
},
|
||||
slug_validator=translation_key_validator,
|
||||
),
|
||||
vol.Optional(
|
||||
"unit_of_measurement"
|
||||
): translation_value_validator,
|
||||
},
|
||||
slug_validator=translation_key_validator,
|
||||
),
|
||||
|
@ -64,10 +64,16 @@ def test_load_translations_files_by_language(
|
||||
"test": {
|
||||
"entity": {
|
||||
"switch": {
|
||||
"other1": {"name": "Other 1"},
|
||||
"other1": {
|
||||
"name": "Other 1",
|
||||
"unit_of_measurement": "units",
|
||||
},
|
||||
"other2": {"name": "Other 2"},
|
||||
"other3": {"name": "Other 3"},
|
||||
"other4": {"name": "Other 4"},
|
||||
"other4": {
|
||||
"name": "Other 4",
|
||||
"unit_of_measurement": "quantities",
|
||||
},
|
||||
"outlet": {"name": "Outlet " "{placeholder}"},
|
||||
}
|
||||
},
|
||||
@ -87,9 +93,11 @@ def test_load_translations_files_by_language(
|
||||
"en",
|
||||
{
|
||||
"component.test.entity.switch.other1.name": "Other 1",
|
||||
"component.test.entity.switch.other1.unit_of_measurement": "units",
|
||||
"component.test.entity.switch.other2.name": "Other 2",
|
||||
"component.test.entity.switch.other3.name": "Other 3",
|
||||
"component.test.entity.switch.other4.name": "Other 4",
|
||||
"component.test.entity.switch.other4.unit_of_measurement": "quantities",
|
||||
"component.test.entity.switch.outlet.name": "Outlet {placeholder}",
|
||||
},
|
||||
[],
|
||||
@ -98,9 +106,11 @@ def test_load_translations_files_by_language(
|
||||
"es",
|
||||
{
|
||||
"component.test.entity.switch.other1.name": "Otra 1",
|
||||
"component.test.entity.switch.other1.unit_of_measurement": "units",
|
||||
"component.test.entity.switch.other2.name": "Otra 2",
|
||||
"component.test.entity.switch.other3.name": "Otra 3",
|
||||
"component.test.entity.switch.other4.name": "Otra 4",
|
||||
"component.test.entity.switch.other4.unit_of_measurement": "quantities",
|
||||
"component.test.entity.switch.outlet.name": "Enchufe {placeholder}",
|
||||
},
|
||||
[],
|
||||
@ -110,12 +120,14 @@ def test_load_translations_files_by_language(
|
||||
{
|
||||
# Correct
|
||||
"component.test.entity.switch.other1.name": "Anderes 1",
|
||||
"component.test.entity.switch.other1.unit_of_measurement": "einheiten",
|
||||
# Translation has placeholder missing in English
|
||||
"component.test.entity.switch.other2.name": "Other 2",
|
||||
# Correct (empty translation)
|
||||
"component.test.entity.switch.other3.name": "",
|
||||
# Translation missing
|
||||
"component.test.entity.switch.other4.name": "Other 4",
|
||||
"component.test.entity.switch.other4.unit_of_measurement": "quantities",
|
||||
# Mismatch in placeholders
|
||||
"component.test.entity.switch.outlet.name": "Outlet {placeholder}",
|
||||
},
|
||||
@ -166,9 +178,11 @@ async def test_get_translations(hass: HomeAssistant, mock_config_flows) -> None:
|
||||
|
||||
assert translations == {
|
||||
"component.test.entity.switch.other1.name": "Other 1",
|
||||
"component.test.entity.switch.other1.unit_of_measurement": "units",
|
||||
"component.test.entity.switch.other2.name": "Other 2",
|
||||
"component.test.entity.switch.other3.name": "Other 3",
|
||||
"component.test.entity.switch.other4.name": "Other 4",
|
||||
"component.test.entity.switch.other4.unit_of_measurement": "quantities",
|
||||
"component.test.entity.switch.outlet.name": "Outlet {placeholder}",
|
||||
}
|
||||
|
||||
@ -176,24 +190,33 @@ async def test_get_translations(hass: HomeAssistant, mock_config_flows) -> None:
|
||||
hass, "de", "entity", {"test"}
|
||||
)
|
||||
|
||||
# Test a partial translation
|
||||
assert translations == {
|
||||
# Correct
|
||||
"component.test.entity.switch.other1.name": "Anderes 1",
|
||||
"component.test.entity.switch.other1.unit_of_measurement": "einheiten",
|
||||
# Translation has placeholder missing in English
|
||||
"component.test.entity.switch.other2.name": "Other 2",
|
||||
# Correct (empty translation)
|
||||
"component.test.entity.switch.other3.name": "",
|
||||
# Translation missing
|
||||
"component.test.entity.switch.other4.name": "Other 4",
|
||||
"component.test.entity.switch.other4.unit_of_measurement": "quantities",
|
||||
# Mismatch in placeholders
|
||||
"component.test.entity.switch.outlet.name": "Outlet {placeholder}",
|
||||
}
|
||||
|
||||
# Test a partial translation
|
||||
translations = await translation.async_get_translations(
|
||||
hass, "es", "entity", {"test"}
|
||||
)
|
||||
|
||||
assert translations == {
|
||||
"component.test.entity.switch.other1.name": "Otra 1",
|
||||
"component.test.entity.switch.other1.unit_of_measurement": "units",
|
||||
"component.test.entity.switch.other2.name": "Otra 2",
|
||||
"component.test.entity.switch.other3.name": "Otra 3",
|
||||
"component.test.entity.switch.other4.name": "Otra 4",
|
||||
"component.test.entity.switch.other4.unit_of_measurement": "quantities",
|
||||
"component.test.entity.switch.outlet.name": "Enchufe {placeholder}",
|
||||
}
|
||||
|
||||
@ -204,9 +227,11 @@ async def test_get_translations(hass: HomeAssistant, mock_config_flows) -> None:
|
||||
|
||||
assert translations == {
|
||||
"component.test.entity.switch.other1.name": "Other 1",
|
||||
"component.test.entity.switch.other1.unit_of_measurement": "units",
|
||||
"component.test.entity.switch.other2.name": "Other 2",
|
||||
"component.test.entity.switch.other3.name": "Other 3",
|
||||
"component.test.entity.switch.other4.name": "Other 4",
|
||||
"component.test.entity.switch.other4.unit_of_measurement": "quantities",
|
||||
"component.test.entity.switch.outlet.name": "Outlet {placeholder}",
|
||||
}
|
||||
|
||||
@ -507,9 +532,11 @@ async def test_get_cached_translations(hass: HomeAssistant, mock_config_flows) -
|
||||
)
|
||||
assert translations == {
|
||||
"component.test.entity.switch.other1.name": "Other 1",
|
||||
"component.test.entity.switch.other1.unit_of_measurement": "units",
|
||||
"component.test.entity.switch.other2.name": "Other 2",
|
||||
"component.test.entity.switch.other3.name": "Other 3",
|
||||
"component.test.entity.switch.other4.name": "Other 4",
|
||||
"component.test.entity.switch.other4.unit_of_measurement": "quantities",
|
||||
"component.test.entity.switch.outlet.name": "Outlet {placeholder}",
|
||||
}
|
||||
|
||||
@ -522,9 +549,11 @@ async def test_get_cached_translations(hass: HomeAssistant, mock_config_flows) -
|
||||
|
||||
assert translations == {
|
||||
"component.test.entity.switch.other1.name": "Otra 1",
|
||||
"component.test.entity.switch.other1.unit_of_measurement": "units",
|
||||
"component.test.entity.switch.other2.name": "Otra 2",
|
||||
"component.test.entity.switch.other3.name": "Otra 3",
|
||||
"component.test.entity.switch.other4.name": "Otra 4",
|
||||
"component.test.entity.switch.other4.unit_of_measurement": "quantities",
|
||||
"component.test.entity.switch.outlet.name": "Enchufe {placeholder}",
|
||||
}
|
||||
|
||||
@ -539,9 +568,11 @@ async def test_get_cached_translations(hass: HomeAssistant, mock_config_flows) -
|
||||
|
||||
assert translations == {
|
||||
"component.test.entity.switch.other1.name": "Other 1",
|
||||
"component.test.entity.switch.other1.unit_of_measurement": "units",
|
||||
"component.test.entity.switch.other2.name": "Other 2",
|
||||
"component.test.entity.switch.other3.name": "Other 3",
|
||||
"component.test.entity.switch.other4.name": "Other 4",
|
||||
"component.test.entity.switch.other4.unit_of_measurement": "quantities",
|
||||
"component.test.entity.switch.outlet.name": "Outlet {placeholder}",
|
||||
}
|
||||
|
||||
@ -678,7 +709,6 @@ async def test_get_translations_still_has_title_without_translations_files(
|
||||
)
|
||||
|
||||
assert translations == translations_again
|
||||
|
||||
assert translations == {
|
||||
"component.component1.title": "Component 1",
|
||||
}
|
||||
|
@ -1,7 +1,10 @@
|
||||
{
|
||||
"entity": {
|
||||
"switch": {
|
||||
"other1": { "name": "Anderes 1" },
|
||||
"other1": {
|
||||
"name": "Anderes 1",
|
||||
"unit_of_measurement": "einheiten"
|
||||
},
|
||||
"other2": { "name": "Anderes 2 {placeholder}" },
|
||||
"other3": { "name": "" },
|
||||
"outlet": { "name": "Steckdose {something}" }
|
||||
|
@ -1,10 +1,13 @@
|
||||
{
|
||||
"entity": {
|
||||
"switch": {
|
||||
"other1": { "name": "Other 1" },
|
||||
"other1": { "name": "Other 1", "unit_of_measurement": "units" },
|
||||
"other2": { "name": "Other 2" },
|
||||
"other3": { "name": "Other 3" },
|
||||
"other4": { "name": "Other 4" },
|
||||
"other4": {
|
||||
"name": "Other 4",
|
||||
"unit_of_measurement": "quantities"
|
||||
},
|
||||
"outlet": { "name": "Outlet {placeholder}" }
|
||||
}
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user