{# This entry is evaluated on a translation-group by translation-group basis, and so far only receives the `translation_group` node. Differences between this and the parent template are: - include region attribute #} {%- macro render_region(translation_group) -%} {%- set reg_nodes = translation_group|xpath('./t/@reg') -%} {%- if reg_nodes|count > 0 -%} ({{ reg_nodes|first }}) {%- endif -%} {%- endmacro -%} {%- macro render_annotation(tg) -%} {# Render the annotation () node, unless it has a @fra_ref. #} {%- set annotations = tg.xpath('./re') %} {% set fra_ref = tg.xpath('./re/@fra_ref')|count > 0 %} {% if annotations|count > 0 and not fra_ref %} ({{ annotations[0].text }}) {% endif -%} {%- endmacro -%} {%- macro render_link(tg, t) -%} {# Render a link to the detailed page. One exception: if the lexicon annotation entry contains a @fra_ref attribute, then we make a reference link, inserting this attribute's value in as a parameter. om to personer --> hverandre: om to personer #} {% set text = t.text %} {% set pos = t.attrib.get('pos', '') %} {%- if pos == 'Pron' and t.attrib.get('type') %} {% set pos_type = t.attrib.get('type')|tagfilter(_from, _to) %} {% set pos_text = pos|tagfilter(_from, _to) + " " + pos_type %} {% else %} {% set pos_text = pos|tagfilter(_from, _to) %} {%- endif %} {% set pos_text = pos_text|trim %} {% set link_target = '' %} {% set fra_ref = tg.xpath('./re/@fra_ref') %} {% set explanation = t.attrib.get('type', False) %} {% set explanation_exists = explanation and True %} {% if fra_ref|count > 0 %} {# If this is a reference link, then there is no data in the node, so the becomes the link text. #} {% set annotations = tg.xpath('./re') %} {% set reference = fra_ref|join('') %} {% set text = annotations[0].text %} {% else %} {% set reference = false %} {% endif %} {% if explanation_exists and explanation == 'expl' %} {% if pos_text|length > 0 %}({{ pos_text }}) {% endif %}{{ text -}} {% else %} {% if reference %} {% if pos_text|length > 0 %}({{ pos_text }}) {% endif %}{{ text -}} → {%- else %} {# NB: swap from and to for these links since these are definitions. #} {% if pos_text|length > 0 %}({{ pos_text }}) {% endif %}{{ text -}} {%- endif %} {%- endif %} {%- endmacro -%} {%- macro render_tg(tg) -%} {# Render all the texts as individual links, followed by a potential annotation. #} {% for t in tg.xpath('./t') %} {{ render_link(tg, t) -}}{% if not loop.last %}, {% endif %} {% endfor %} {{- render_annotation(tg) -}} {%- endmacro -%} {%- if translation_group -%} {{- render_region(translation_group) -}}{{ render_tg(translation_group) }} {%- endif -%} {# vim: set ts=4 sw=4 tw=72 syntax=htmljinja : #}