From 4f545c0a817e446b04d449ffb799445762d222ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ab=C3=ADlio=20Costa?= Date: Wed, 20 Nov 2024 17:43:49 +0000 Subject: [PATCH] Add section for unit of measurement translations (#2451) Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> --- docs/internationalization/core.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/internationalization/core.md b/docs/internationalization/core.md index 4294e063..a5d07517 100644 --- a/docs/internationalization/core.md +++ b/docs/internationalization/core.md @@ -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 Assistant’s translation directories by running the following script: