Example #1
0
    def load_unit_tree(input_file):
        """Return a dict with the translations grouped by files ODF package.

        The keys are the filenames inside the template ODF package, and the
        values are XPathTree instances for each of those files.
        """
        store = factory.getobject(input_file)
        tree = build_unit_tree(store)

        def extract_unit_tree(filename, root_dom_element_name):
            """Find the subtree in 'tree' which corresponds to the data in XML
            file 'filename'.
            """
            try:
                file_tree = tree.children[root_dom_element_name, 0]
            except KeyError:
                file_tree = XPathTree()

            return (filename, file_tree)

        return dict([
            extract_unit_tree('content.xml', 'office:document-content'),
            extract_unit_tree('meta.xml', 'office:document-meta'),
            extract_unit_tree('styles.xml', 'office:document-styles')
        ])
Example #2
0
        def extract_unit_tree(filename, root_dom_element_name):
            """Find the subtree in 'tree' which corresponds to the data in XML
            file 'filename'
            """
            tree = build_unit_tree(store, filename)

            try:
                file_tree = tree.children[root_dom_element_name, 0]
            except KeyError:
                file_tree = XPathTree()

            return (filename, file_tree)
Example #3
0
        def extract_unit_tree(filename, root_dom_element_name):
            """Find the subtree in 'tree' which corresponds to the data in XML
            file 'filename'
            """
            tree = build_unit_tree(store, filename)

            try:
                file_tree = tree.children[root_dom_element_name, 0]
            except KeyError:
                file_tree = XPathTree()

            return (filename, file_tree)
Example #4
0
    def load_unit_tree(input_file, dom_trees):
        store = factory.getobject(input_file)
        tree = unit_tree.build_unit_tree(store)

        def extract_unit_tree(filename, root_dom_element_name):
            """Find the subtree in 'tree' which corresponds to the data in XML file 'filename'"""
            def get_tree():
                try:
                    return tree.children['office:%s' % root_dom_element_name, 0]
                except KeyError:
                    return unit_tree.XPathTree()
            return (filename, get_tree())

        return dict([extract_unit_tree('content.xml', 'document-content'),
                     extract_unit_tree('meta.xml',    'document-meta'),
                     extract_unit_tree('styles.xml',  'document-styles')])
Example #5
0
    def load_unit_tree(input_file):
        """Return a dict with the translations grouped by files ODF package.

        The keys are the filenames inside the template ODF package, and the
        values are XPathTree instances for each of those files.
        """
        store = factory.getobject(input_file)
        tree = build_unit_tree(store)

        def extract_unit_tree(filename, root_dom_element_name):
            """Find the subtree in 'tree' which corresponds to the data in XML
            file 'filename'.
            """
            try:
                file_tree = tree.children[root_dom_element_name, 0]
            except KeyError:
                file_tree = XPathTree()

            return (filename, file_tree)

        return dict([extract_unit_tree('content.xml', 'office:document-content'),
                     extract_unit_tree('meta.xml', 'office:document-meta'),
                     extract_unit_tree('styles.xml', 'office:document-styles')])