Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
PiotrMachowski authored Feb 3, 2023
1 parent 72c6487 commit 93217b6
Showing 1 changed file with 94 additions and 78 deletions.
172 changes: 94 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
This integration adds possibility to use new functions in Home Assistant Jinja2 templating engine:
- `ct_state_translated` - returns translated state of an entity
- `ct_translated` - returns translation for a given key
- `ct_all_translations` - returns all available translation keys (that can be used with `ct_translated`)
- `ct_all_translations` - returns all available translations (that can be used with `ct_translated`)
- `ct_eval` - evaluates text as a template

## Usage
Expand All @@ -47,127 +47,143 @@ This integration adds possibility to use new functions in Home Assistant Jinja2
This function returns translated state of an entity.

<table>
<tr>
<th>
Input
</th>
<th>
Output
</th>
</tr>
<tr>
<td>
<pre>
<tr>
<th>
Input
</th>
<th>
Output
</th>
</tr>
<tr>
<td>

```
State: {{ states("sun.sun") }}
Translated en: {{ ct_state_translated("sun.sun", "en") }}
Translated en: {{ "sun.sun" | ct_state_translated("en") }}
Translated nl: {{ ct_state_translated("sun.sun", "nl") }}
Translated nl: {{ "sun.sun" | ct_state_translated("nl") }}
</pre>
</td>
<td>
<pre>
```

</td>
<td>

```
State: below_horizon
Translated en: Below horizon
Translated en: Below horizon
Translated nl: Onder de horizon
Translated nl: Onder de horizon
</pre>
</td>
</tr>
```

</td>
</tr>
</table>

### `ct_translated`

This function returns translation for a given key. You can use `ct_all_translations` to check available keys.

<table>
<tr>
<th>
Input
</th>
<th>
Output
</th>
</tr>
<tr>
<td>
<pre>
Translated en: {{ ct_state_translated("component.sun.state._.below_horizon", "en") }}
Translated en: {{ "component.sun.state._.below_horizon" | ct_state_translated("en") }}
Translated nl: {{ ct_state_translated("component.sun.state._.below_horizon", "nl") }}
Translated nl: {{ "component.sun.state._.below_horizon" | ct_state_translated("nl") }}
</pre>
</td>
<td>
<pre>
<tr>
<th>
Input
</th>
<th>
Output
</th>
</tr>
<tr>
<td>

```yaml
Translated en: {{ ct_translated("component.sun.state._.below_horizon", "en") }}
Translated en: {{ "component.sun.state._.below_horizon" | ct_translated("en") }}
Translated nl: {{ ct_translated("component.sun.state._.below_horizon", "nl") }}
Translated nl: {{ "component.sun.state._.below_horizon" | ct_translated("nl") }}
```
</td>
<td>
```
Translated en: Below horizon
Translated en: Below horizon
Translated nl: Onder de horizon
Translated nl: Onder de horizon
</pre>
</td>
</tr>
```
</td>
</tr>
</table>
### `ct_all_translations`

This function returns translation for a given key.
This function returns all available translations.

<table>
<tr>
<th>
Input
</th>
<th>
Output
</th>
</tr>
<tr>
<td>
<pre>
<tr>
<th>
Input
</th>
<th>
Output
</th>
</tr>
<tr>
<td>

```
{{ ct_all_translations("en") }}
</pre>
</td>
<td>
<pre>
```
</td>
<td>
```json
{
"component.sun.state._.above_horizon": "Above horizon",
"component.sun.state._.below_horizon": "Below horizon"
}
</pre>
</td>
</tr>
```

</td>
</tr>
</table>

### `ct_eval`

This function evaluates text as a template.

<table>
<tr>
<th>
Input
</th>
<th>
Output
</th>
</tr>
<tr>
<td>
<pre>
<tr>
<th>
Input
</th>
<th>
Output
</th>
</tr>
<tr>
<td>

```yaml
{% set template_text = "{{ states('sun.sun') }}" %}
{{ ct_eval(template_text) }}
{{ template_text | ct_eval }}
</pre>
</td>
<td>
<pre>
```

</td>
<td>

```
below_horizon
below_horizon
</pre>
</td>
</tr>
```

</td>
</tr>
</table>

## Configuration
Expand Down

0 comments on commit 93217b6

Please sign in to comment.