Example #1
0
    def visit_entity(self, node, node_info):
        string, translation = node_info

        # Strip tags out of translation if they exist.
        tags = []
        tag_matches = list(re.finditer(TAG_REGEX, translation))
        if tag_matches:
            tags = [m.group(1) for m in tag_matches]
            translation = translation[:tag_matches[0].start()].strip()

        if translation == '':
            raise ParsimoniousParseError(
                'Blank translation for key {key} is not allowed in langfiles.'.
                format(key=string))

        return LangEntity(string, translation, tags)
                           node_text(end))

    def visit_blank_line(self, node, (whitespace, newline)):
        return BLANK_LINE

    def visit_entity(self, node, (string, translation)):
        # Strip tags out of translation if they exist.
        tags = []
        tag_matches = list(re.finditer(TAG_REGEX, translation))
        if tag_matches:
            tags = [m.group(1) for m in tag_matches]
            translation = translation[:tag_matches[0].start()].strip()

        if translation == '':
            raise ParsimoniousParseError(
                'Blank translation for key {key} is not allowed in langfiles.'.
                format(key=string))

        return LangEntity(string, translation, tags)

    def visit_string(self, node, (marker, content, end)):
        return content.text.strip()

    def visit_translation(self, node, (content, end)):
        return content.text.strip()

    def generic_visit(self, node, children):
        if children and len(children) == 1:
            return children[0]
        else:
            return children or node