Add section for unit of measurement translations (#2451)

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
Abílio Costa 2024-11-20 17:43:49 +00:00 committed by GitHub
parent cf52c30bc0
commit 4f545c0a81
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -467,6 +467,24 @@ If your integration provides entities under its domain, you will want to transla
}
```
#### Unit of measurement of entities
Integrations can provide translations for units of measurement of its entities. To do this, provide an `entity` object, that contains translations for the units and set the entity's `translation_key` property to a key under a domain in the `entity` object.
If the entity's `translation_key` property is not `None` and the `entity` object provides a translated unit, `SensorEntityDescription.native_unit_of_measurement` and `NumberEntityDescription.native_unit_of_measurement` will be ignored.
The following example `strings.json` is for a `sensor` entity with its `translation_key` property set to `goal`:
```json
{
"entity": {
"sensor": {
"goal": {
"unit_of_measurement": "steps"
}
}
}
}
```
## Test translations
In order to test changes to translation files, the translation strings must be compiled into Home Assistants translation directories by running the following script: