Document device translations (#2096)

* Document device translations

* Update docs/internationalization/core.md

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update docs/internationalization/core.md

* Update docs/internationalization/core.md

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
Erik Montnemery 2024-03-03 10:39:06 +01:00 committed by GitHub
parent db434eb7bd
commit cdcf0a1fe2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -12,6 +12,7 @@ The `strings.json` contains translations for different things that the integrati
| ------------------- | ------------------------------------------------- |
| `title` | Title of the integration. |
| `config` | Translations for the config flow. |
| `device` | Translations for devices. |
| `device_automation` | Translations for device automations. |
| `entity` | Translations for entities. |
| `entity_component` | Translations for entity components. |
@ -224,6 +225,37 @@ The translation strings for repairs issues are defined under the `issues` key. A
}
```
### Devices
#### Name of devices
Integrations can provide translations for names of its devices. To do this, provide a `device` object, that contains translations of the names and set the device's `translation_key` to a key under a domain in the `device` object.
If the device's `translation_key` is not `None`, the `name` which is either set in an entity's `device_info` property or passed to `DeviceRegistry.async_get_or_create`, will be ignored. If the `device` object does not provide a translated name for the specified `translation_key`, the `translation_key` will be used as device name.
It is also supported to use placeholders within the translation. If a placeholder is defined within the translation string, the device's `translation_placeholders` has to be set accordingly.
The following example `strings.json` is for a device with its `translation_key` set to `power_strip`:
```json
{
"device": {
"power_strip": {
"name": "Power strip"
}
}
}
```
The following example `strings.json` is for a device with its `translation_key` property set to `n_ch_power_strip` and a placeholder `number_of_sockets`:
```json
{
"device": {
"n_ch_power_strip": {
"name": "Power strip with {number_of_sockets} sockets"
}
}
}
```
### Entities
#### Name of entities