Esempio n. 1
0
    def xliff_export(self, targetlang, export_all=1, REQUEST=None,
                     RESPONSE=None):
        """ Exports the content of the message catalog to an XLIFF file
        """
        orglang = self._default_language
        export_all = int(export_all)
        from DateTime import DateTime

        # Generate the XLIFF file header
        RESPONSE.setHeader('Content-Type', 'text/xml; charset=UTF-8')
        RESPONSE.setHeader('Content-Disposition',
           'attachment; filename="%s_%s_%s.xlf"' % ( self.id, orglang,
                                                     targetlang ))

        # build data structure for the xml header
        xml_header = {}
        xml_header['standalone'] = -1
        xml_header['xml_version'] = u'1.0'
        xml_header['document_type'] = (u'xliff',
              u'http://www.oasis-open.org/committees/xliff/documents/xliff.dtd')

        version = u'1.0'

        # build the data-stucture for the File tag
        attributes = {}
        attributes['original'] = u'/%s' % self.absolute_url(1)
        attributes['product-name'] = u'Localizer'
        attributes['product-version'] = u'1.1.x'
        attributes['data-type'] = u'plaintext'
        attributes['source-language'] = orglang
        attributes['target-language'] = targetlang
        attributes['date'] = DateTime().HTML4()

        # Get the messages, and perhaps its translations.
        d = {}

        for prop in self._local_properties.keys():
            target, fuzzy = self.get_localproperty(prop, targetlang)
            msgkey, fuzzy = self.get_localproperty(prop, self._default_language)
            # if export_all=1 export all messages otherwise export
            # only untranslated messages
            if export_all or not target:
                id = md5text(msgkey)
                if target:
                    t = Translation(msgkey, target, {'id':id})
                else:
                    t = Translation(msgkey, msgkey, {'id':id})
                d[msgkey] = t

        files = [xliff_File(d, attributes)]

        xliff = XLIFF()
        xliff.build(xml_header, version, files)

        return xliff.to_str()
Esempio n. 2
0
    def xliff_export(self, x, export_all=1, REQUEST=None, RESPONSE=None):
        """Exports the content of the message catalog to an XLIFF file
        """
        orglang = self._default_language
        export_all = int(export_all)
        from DateTime import DateTime

        # Generate the XLIFF file header
        RESPONSE.setHeader("Content-Type", "text/xml; charset=UTF-8")
        RESPONSE.setHeader("Content-Disposition", 'attachment; filename="%s_%s_%s.xlf"' % (self.id, orglang, x))
        # build data structure for the xml header
        xml_header = {}
        xml_header["standalone"] = -1
        xml_header["xml_version"] = u"1.0"
        xml_header["document_type"] = (u"xliff", u"http://www.oasis-open.org/committees/xliff/documents/xliff.dtd")

        version = u"1.0"

        # build the data-stucture for the File tag
        attributes = {}
        attributes["original"] = u"/%s" % self.absolute_url(1)
        attributes["product-name"] = u"Localizer"
        attributes["product-version"] = u"1.1.x"
        attributes["data-type"] = u"plaintext"
        attributes["source-language"] = orglang
        attributes["target-language"] = x
        attributes["date"] = DateTime().HTML4()

        # Get the messages, and perhaps its translations.
        d = {}
        for msgkey, transunit in self._messages.items():
            target = transunit.get(x, "")
            # if export_all=1 export all messages otherwise export
            # only untranslated messages
            if export_all or not target:
                id = md5text(msgkey)
                notes = []
                if transunit.has_key("note") and transunit["note"]:
                    notes = [xliff_Note(transunit["note"])]
                if target:
                    t = Translation(msgkey, target, {"id": id}, notes)
                else:
                    t = Translation(msgkey, msgkey, {"id": id}, notes)
                d[msgkey] = t

        files = [xliff_File(d, attributes)]

        xliff = XLIFF()
        xliff.build(xml_header, version, files)

        return xliff.to_str()