From cdcf0a1fe295497590f0306e5a02ae0cedd272a9 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Sun, 3 Mar 2024 10:39:06 +0100 Subject: [PATCH] Document device translations (#2096) * Document device translations * Update docs/internationalization/core.md Co-authored-by: Martin Hjelmare * Update docs/internationalization/core.md * Update docs/internationalization/core.md --------- Co-authored-by: Martin Hjelmare --- docs/internationalization/core.md | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/docs/internationalization/core.md b/docs/internationalization/core.md index 59043c33..e720fdbf 100644 --- a/docs/internationalization/core.md +++ b/docs/internationalization/core.md @@ -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