mirror of
https://github.com/home-assistant/developers.home-assistant.git
synced 2025-07-14 12:56:30 +00:00
Add blogpost about translation placeholders (#2046)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
735b7c04b3
commit
bd7a29ef66
44
blog/2024-01-19-entity-translations-placeholders.md
Normal file
44
blog/2024-01-19-entity-translations-placeholders.md
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
---
|
||||||
|
author: Joost Lekkerkerker
|
||||||
|
authorURL: https://github.com/joostlek
|
||||||
|
authorImageURL: https://avatars.githubusercontent.com/u/7083755?v=4
|
||||||
|
title: "Introducing entity translation placeholders"
|
||||||
|
---
|
||||||
|
|
||||||
|
It's now possible to provide static values to be used in an entity translation using placeholders.
|
||||||
|
You can pass placeholders via the `translation_placeholders` property of an entity.
|
||||||
|
|
||||||
|
An example sensor:
|
||||||
|
```python
|
||||||
|
class TestEntity(SensorEntity):
|
||||||
|
"""Example entity."""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
_attr_translation_key = "temperature"
|
||||||
|
|
||||||
|
def __init__(self) -> None:
|
||||||
|
"""Initialize example entity."""
|
||||||
|
self._attr_translation_placeholders = {"channel_id": "2"}
|
||||||
|
self._attr_device_info = DeviceInfo(
|
||||||
|
name="Example device"
|
||||||
|
)
|
||||||
|
```
|
||||||
|
The `strings.json` file would look like:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"entity": {
|
||||||
|
"sensor": {
|
||||||
|
"temperature": {
|
||||||
|
"name": "Temperature channel {channel_id}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The resulting entity would be called `Example device Temperature channel 2`.
|
||||||
|
|
||||||
|
A warning is logged once when a translation placeholder is expected but not provided by the entity.
|
||||||
|
When this happens on a system that is not on a stable version (dev, nightly, or beta), an error will be raised to be able to catch the mistakes quickly.
|
||||||
|
|
||||||
|
Please don't forget to be kind towards your translators, as they need to understand what kind of name or value will be passed in from the placeholder name ❤️.
|
Loading…
x
Reference in New Issue
Block a user