Important
This template is based on a template idea by @jazzyisj. Please check out their repository for a version that works with English text and leave a star: https://github.com/jazzyisj/speech-helpers-jinja/
You can also find it in inside HACS in Home Assistant under the name Jinja Speech Helpers.
This template contains Jinja macros that work with German text. One use-case for those macros are notification messages where you don't know if a word needs to be singular or plural. The macros will look at the given quantity and use the correct words.
There are more macros for other formatting needs. Check out the documentation below.
Without HACS
- Download the contents from speech_helpers_german.jinja from the master-branch.
- Add the file to your
<config>/custom_templates
-folder. - Reload your configuration from within the developer tools in Home Assistant.
- The template should now be ready for use.
With HACS
- Search for "Jinja Speech Helpers German" in HACS.
- Download the repository via HACS.
- The template should now be ready for use.
You can also use this button to add the repository to your Home Assistant instance via HACS:
Looks at the given quantity and depending on it, returns word_singular
or word_plural
.
plural(word_singular, word_plural, quantity, show_quantity=true)
Param | Type | Explanation |
---|---|---|
word_singular |
string | Will be used as the output if quantity is 1. |
word_plural |
string | Will be used as the output if quantity is 0 or above 1. |
quantity |
number | The quantity of the word that should be pluralized. |
show_quantity |
boolean | Will add the given quantity to the output infront of the word. (Default: true ) |
Input
{% from 'speech_helpers_german.jinja' import plural %}
Du hast {{ plural('Apfel', 'Äpfel', 3) }}.
Es gibt ein Problem mit {{ plural('der Lampe', 'den Lampen', 1, false) }}.
Output
Du hast 3 Äpfel.
Es gibt ein Problem mit der lampe.
Looks at the given quantity and depending on it, returns the words "ist" or "sind".
plural_verb(quantity)
Param | Type | Explanation |
---|---|---|
quantity |
number | If it is 1 "ist" will be returned. Otherwise, "sind" will be returned. |
Input
{% from 'speech_helpers_german.jinja' import plural_verb %}
Folgende Tür(en) {{ plural_verb(2) }} offen: ...
Output
Folgende Tür(en) sind offen: ...
Works like a combination of plural
and plural_verb
. It looks at the given quantity and uses the corresponding word but also adds the correct verb before or after the word.
plural_word_and_verb(word_singular, word_plural, quantity, show_quantity=true, verb_first=true)
Param | Type | Explanation |
---|---|---|
word_singular |
string | Will be used as the output if quantity is 1. |
word_plural |
string | Will be used as the output if quantity is 0 or above 1. |
quantity |
number | The quantity of the word that should be pluralized. Also decides if the verb should be "ist" (singular) or "sind" (plural). |
show_quantity |
boolean | Will add the given quantity to the output infront of the word. (Default: true ) |
verb_first |
boolean | Decides if the verb should be added before the number and word or after (see examples below). (Default: true ) |
Input
{% from 'speech_helpers_german.jinja' import plural_word_and_verb %}
Es {{ plural_word_and_verb('Tür', 'Türen', 0) }} offen.
{{ plural_word_and_verb('Tür', 'Türen', 1, true, false) }} gekippt.
{{ plural_word_and_verb('Ein Licht', 'Mehrere Lichter', 5, false, false) }} angeschaltet.
Output
Es sind 0 Türen offen.
1 Tür ist gekippt.
Mehrere Lichter sind angeschlatet.
Converts an array of strings into a single string with (comma-)separated elements. By default the separator used will be ", " and the last separator will be replaced by " und ". You can also convert the elements from the array into title-case.
array_to_separated_list(array, separator=', ', replace_last_separator=true, convert_to_title=false)
Param | Type | Explanation |
---|---|---|
array | list of strings | The array of strings that should be converted. |
separator | string | The string that is added between the elements during convertion. (Default: ', ' ) |
replace_last_separator | boolean | If true , the last separator will be replaced by " und ". (Default: true ) |
convert_to_title | boolean | If true , the elements of the array will be converted into title-case. (Default: false ) |
Input
{% from 'speech_helpers_german.jinja' import array_to_separated_list %}
{{ array_to_separated_list(['foo', 'bar', 'test']) }}
{{ array_to_separated_list(['foo', 'bar', 'test'], convert_to_title=true) }}
{{ array_to_separated_list(['foo', 'bar', 'test'], ' & ', false) }}
{{ array_to_separated_list(['foo', 'bar', 'test'], replace_last_separator=false) }}
Output
foo, bar und test
Foo, Bar und Test
foo & bar & test
foo, bar, test
Converts an array of strings into a bullet point list. At the end of each bullet point, an <br/>
is added. This will be converted into line breaks when using the output for phone notifications or HTML5 Push Notifications.
array_to_bullet_points_list(array, bullet_symbol='- ')
Param | Type | Explanation |
---|---|---|
array | list of strings | The array of strings that should be converted. |
bullet_symbol | string | The string that should be added at the beginning of every line as the bullet point symbol. (Default: '- ' ) |
Input
{% from 'speech_helpers_german.jinja' import array_to_bullet_points_list %}
{{ array_to_bullet_points_list(['foo', 'bar', 'test']) }}
{{ array_to_bullet_points_list(['foo', 'bar', 'test'], '‣ ') }}
Output Raw
- foo<br/>- bar<br/>- test<br/>
‣ foo<br/>‣ bar<br/>‣ test<br/>
Output in Notification
- foo
- bar
- test
‣ foo
‣ bar
‣ test