Example #1
0
def definition_link(context, slug: str) -> str:
    """
    Links to the definition of the wordform. Outputs wordform with current orthography.

    Warning: currently incurs a database query for every such link.
    """
    wordform = Wordform.objects.get(slug=slug)
    return format_html(
        '<a href="{}">{}</a>',
        reverse("cree-dictionary-index-with-lemma", kwargs=dict(slug=slug)),
        orth_tag(context, wordform.text),
    )
Example #2
0
def relabel(context: Context, tags: Sequence[FSTTag], labels=None):
    """
    Gets the best matching label for the given object.
    """

    if labels is None:
        label_setting = label_setting_from_context(context)
    else:
        label_setting = labels

    relabeller = label_setting_to_relabeller(label_setting)

    if label := relabeller.get_longest(tags):
        if label_setting == "source_language":
            return orth_tag(context, label)
        return label
Example #3
0
def cree_example(context, example):
    """
    Similar to {% orth %}, but does not convert the 'like: ' prefix.
    This should be used for the examples given in crk.altlabel.tsv.

    e.g.,

        {% cree_example 'like: wâpamêw' %}

    Yields:

        like: <span lang="cr" data-orth
              data-orth-latn="wâpamêw"
              data-orth-latn-x-macron="wāpamēw"
              data-orth-cans="ᐚᐸᒣᐤ">wâpamêw</span>
    """
    if not example.startswith("like: "):
        # Do nothing if it doesn't look like an example
        return example

    _like, _sp, cree = example.partition(" ")
    return format_html("like: {}", orth_tag(context, cree))