Exemple #1
0
 def translate_dom_trees(unit_trees, dom_trees):
     make_parse_state = lambda: extract.ParseState(
         odf_shared.no_translate_content_elements, odf_shared.inline_elements
     )
     for filename, dom_tree in dom_trees.iteritems():
         file_unit_tree = unit_trees[filename]
         generate.apply_translations(dom_tree.getroot(), file_unit_tree, generate.replace_dom_text(make_parse_state))
     return dom_trees
Exemple #2
0
    def translate_dom_trees(unit_trees, dom_trees):
        """Return a dict with the translated files for the IDML package.

        The keys are the filenames for the translatable files inside the
        template IDML package, and the values are etree ElementTree instances
        for each of those files.
        """
        def get_po_doms(unit):
            """Return a tuple with unit source and target DOM objects.

            This method is method is meant to provide a way to retrieve the DOM
            objects for the unit source and target for PO stores.

            Since POunit doesn't have any source_dom nor target_dom attributes,
            it is necessary to craft those objects.
            """
            def add_node_content(string, node):
                """Append the translatable content to the node.

                The string is going to have XLIFF placeables, so we have to
                parse it as XML in order to get the right nodes to append to
                the node.
                """
                # Add a wrapper "whatever" tag to avoid problems when parsing
                # several sibling tags at the root level.
                fake_string = "<whatever>" + string + "</whatever>"

                # Copy the children to the XLIFF unit's source or target node.
                fake_node = etree.fromstring(fake_string)
                node.extend(fake_node.getchildren())

                return node

            source_dom = etree.Element("source")
            source_dom = add_node_content(unit.source, source_dom)
            target_dom = etree.Element("target")

            if unit.target:
                target_dom = add_node_content(unit.target, target_dom)
            else:
                target_dom = add_node_content(unit.source, target_dom)

            return (source_dom, target_dom)

        make_parse_state = lambda: ParseState(NO_TRANSLATE_ELEMENTS,
                                              INLINE_ELEMENTS)
        for filename, dom_tree in dom_trees.items():
            file_unit_tree = unit_trees[filename]
            apply_translations(
                dom_tree.getroot(),
                file_unit_tree,
                replace_dom_text(
                    make_parse_state,
                    dom_retriever=get_po_doms,
                    process_translatable=process_idml_translatable,
                ),
            )
        return dom_trees
Exemple #3
0
 def translate_dom_trees(unit_trees, dom_trees):
     make_parse_state = lambda: extract.ParseState(
         odf_shared.no_translate_content_elements, odf_shared.
         inline_elements)
     for filename, dom_tree in dom_trees.iteritems():
         file_unit_tree = unit_trees[filename]
         generate.apply_translations(
             dom_tree.getroot(), file_unit_tree,
             generate.replace_dom_text(make_parse_state))
     return dom_trees
Exemple #4
0
    def translate_dom_trees(unit_trees, dom_trees):
        """Return a dict with the translated files for the IDML package.

        The keys are the filenames for the translatable files inside the
        template IDML package, and the values are etree ElementTree instances
        for each of those files.
        """
        def get_po_doms(unit):
            """Return a tuple with unit source and target DOM objects.

            This method is method is meant to provide a way to retrieve the DOM
            objects for the unit source and target for PO stores.

            Since POunit doesn't have any source_dom nor target_dom attributes,
            it is necessary to craft those objects.
            """
            def add_node_content(string, node):
                """Append the translatable content to the node.

                The string is going to have XLIFF placeables, so we have to
                parse it as XML in order to get the right nodes to append to
                the node.
                """
                # Add a wrapper "whatever" tag to avoid problems when parsing
                # several sibling tags at the root level.
                fake_string = "<whatever>" + string + "</whatever>"

                # Copy the children to the XLIFF unit's source or target node.
                fake_node = etree.fromstring(fake_string)
                node.extend(fake_node.getchildren())

                return node

            source_dom = etree.Element("source")
            source_dom = add_node_content(unit.source, source_dom)
            target_dom = etree.Element("target")

            if unit.target:
                target_dom = add_node_content(unit.target, target_dom)
            else:
                target_dom = add_node_content(unit.source, target_dom)

            return (source_dom, target_dom)

        make_parse_state = lambda: ParseState(NO_TRANSLATE_ELEMENTS,
                                              INLINE_ELEMENTS)
        for filename, dom_tree in six.iteritems(dom_trees):
            file_unit_tree = unit_trees[filename]
            apply_translations(dom_tree.getroot(), file_unit_tree,
                               replace_dom_text(make_parse_state,
                                                dom_retriever=get_po_doms,
                                                process_translatable=process_idml_translatable))
        return dom_trees
Exemple #5
0
    def translate_dom_trees(unit_trees, dom_trees):
        """Return a dict with the translated files for the ODF package.

        The keys are the filenames for the translatable files inside the
        template ODF package, and the values are etree ElementTree instances
        for each of those files.
        """
        make_parse_state = lambda: ParseState(no_translate_content_elements,
                                              inline_elements)
        for filename, dom_tree in six.iteritems(dom_trees):
            file_unit_tree = unit_trees[filename]
            apply_translations(dom_tree.getroot(), file_unit_tree,
                               replace_dom_text(make_parse_state))
        return dom_trees
Exemple #6
0
    def translate_dom_trees(unit_trees, dom_trees):
        """Return a dict with the translated files for the ODF package.

        The keys are the filenames for the translatable files inside the
        template ODF package, and the values are etree ElementTree instances
        for each of those files.
        """
        make_parse_state = lambda: ParseState(no_translate_content_elements,
                                              inline_elements)
        for filename, dom_tree in six.iteritems(dom_trees):
            file_unit_tree = unit_trees[filename]
            apply_translations(dom_tree.getroot(), file_unit_tree,
                               replace_dom_text(make_parse_state))
        return dom_trees