Esempio n. 1
0
 def convertstore(self, inputstore, templatefile=None, context=None):
     """converts a .po file to .ts format (using a template .ts file if given)"""
     if templatefile is None:
         tsfile = ts.QtTsParser()
     else:
         tsfile = ts.QtTsParser(templatefile)
     for inputunit in inputstore.units:
         if inputunit.isheader() or inputunit.is_blank:
             continue
         source = inputunit.source
         translation = inputunit.target
         comment = inputunit.getnotes("translator")
         transtype = None
         if not inputunit.istranslated():
             transtype = "unfinished"
         elif inputunit.getnotes("developer") == "(obsolete)":
             transtype = "obsolete"
         if isinstance(source, str):
             source = source.decode("utf-8")
         if isinstance(translation, str):
             translation = translation.decode("utf-8")
         for sourcelocation in inputunit.getlocations():
             if context is None:
                 if "#" in sourcelocation:
                     contextname = sourcelocation[:sourcelocation.find("#")]
                 else:
                     contextname = sourcelocation
             else:
                 contextname = context
             tsfile.addtranslation(contextname, source, translation, comment, transtype, createifmissing=True)
     return tsfile.getxml()
Esempio n. 2
0
 def test_construct():
     tsfile = ts.QtTsParser()
     tsfile.addtranslation("ryan",
                           "Bread",
                           "Brood",
                           "Wit",
                           createifmissing=True)
Esempio n. 3
0
    def convertfile(self, inputfile):
        """converts a .ts file to .po format"""
        tsfile = ts.QtTsParser(inputfile)
        thetargetfile = po.pofile()

        for contextname, messages in tsfile.iteritems():
            messagenum = 0
            for message in messages:
                messagenum += 1
                source = tsfile.getmessagesource(message)
                translation = tsfile.getmessagetranslation(message)
                comment = tsfile.getmessagecomment(message)
                transtype = tsfile.getmessagetype(message)
                thepo = self.convertmessage(contextname, messagenum, source, translation, comment, transtype)
                thetargetfile.addunit(thepo)
        thetargetfile.removeduplicates(self.duplicatestyle)
        return thetargetfile