'Replace the <var>s with the correct plural() contents.
If the first argument to plural() is a string:
This means that the plural() function is expected to output just
the pluralized form of the string itself. We take this and turn
it into two blocks toggled with an if/else and with the string
hardcoded into it. For example:
<p>I have <var>plural("a cat", NUM)</var>.</p>
Would then become (after user prompting):
<p data-if="isSingular(NUM)">I have a cat.</p>
<p data-else>I have many cats.</p>
If the second argument to plural() is a string:
This means that the plural() function is expected to output a
number and the pluralized form of the string. We take this and turn
it into two blocks toggled with an if/else and with the number
variable and the string hardcoded into it. For example:
<p>I have <var>plural(NUM, "cat")</var>.</p>
Would then become (after user prompting):
<p data-if="isSingular(NUM)">I have <var>NUM</var> cat.</p>
<p data-else>I have <var>NUM</var> cats.</p>
Otherwise both of the results are variables or function calls:
This means that we need to insert the variables directly, for example:
<p>I have <var>plural(NUM, item(1))</var>.</p>
Would then become (after user prompting):
<p data-if="isSingular(NUM)">I have <var>NUM</var>
<var>item(1)</var>.</p>
<p data-else>I have <var>NUM</var>
<var>plural_form(item(1), NUM)</var>.</p>
To do this we need to determine which argument is the number variable
and then change the output depending upon it (because of the silly
plural() function argument order).'

def filter_var(self, match, var_node):

    cloned_var = self._get_cloned_var(var_node)
    first_str_match = _STRING_RE.match(match.group(2))
    second_str_match = _STRING_RE.match(match.group(3))
    if first_str_match:
        word = first_str_match.group(1).strip()
        _replace_node(var_node, word)
        _replace_node(cloned_var, get_plural_form(word))
    elif second_str_match:
        word = second_str_match.group(1).strip()
        var_node.text = cloned_var.text = match.group(2).strip()
        var_node.tail = (('    ' + word) + (var_node.tail or ''))
        cloned_var.tail = (('    ' + get_plural_form(word)) + (cloned_var.tail or ''))
    else:
        plural_num_pos = get_plural_num_pos(match)
        check_str = (match.group(3) if (plural_num_pos == 1) else match.group(2))
        if _check_plural_is_ambiguous(check_str):
            pluralize = 'AMBIGUOUS_PLURAL(%s,    %s)'
        else:
            pluralize = self._function_map[match.group(1)]
        if (plural_num_pos == 1):
            var_node.text = cloned_var.text = match.group(2).strip()
            singular_var_node = var_node.makeelement('var')
            plural_var_node = cloned_var.makeelement('var')
            singular_var_node.text = match.group(3).strip()
            plural_var_node.text = (pluralize % (match.group(3).strip(), match.group(2).strip()))
            var_node.addnext(singular_var_node)
            cloned_var.addnext(plural_var_node)
            var_node.tail = cloned_var.tail = '    '
        else:
            var_node.text = match.group(2).strip()
            cloned_var.text = (pluralize % (match.group(2).strip(), match.group(3).strip()))
    return True
