예제 #1
0
 def convertstore(inputstore, outputfile, templatefile=None, context=None):
     """converts a .po file to .ts format (using a template .ts file if given)"""
     if templatefile is None:
         tsfile = ts2.tsfile()
     else:
         tsfile = ts2.tsfile(templatefile)
     for inputunit in inputstore.units:
         if inputunit.isheader() or inputunit.isblank():
             continue
         source = inputunit.source
         translation = inputunit.target
         comment = inputunit.getnotes("translator")
         for sourcelocation in inputunit.getlocations():
             if context is None:
                 if "#" in sourcelocation:
                     contextname = sourcelocation[: sourcelocation.find("#")]
                 else:
                     contextname = sourcelocation
             else:
                 contextname = context
             tsunit = ts2.tsunit(source)
             tsunit.target = translation
             if not inputunit.istranslated():
                 tsunit.markfuzzy()
             elif inputunit.getnotes("developer") == "(obsolete)":
                 tsunit.set_state_n(tsunit.S_OBSOLETE)
             tsfile.addunit(tsunit, True, contextname, comment, True)
     tsfile.serialize(outputfile)
예제 #2
0
 def test_target(self):
     tsfile = ts.tsfile()
     tsunit = tsfile.addsourceunit("Concept")
     tsunit.target = "Konsep"
     newfile = ts.tsfile.parsestring(bytes(tsfile))
     print(bytes(tsfile))
     assert newfile.findunit("Concept").target == "Konsep"
예제 #3
0
    def convertfile(self, inputfile):
        """converts a .ts file to .po format"""
        tsfile = ts2.tsfile(inputfile)
        thetargetfile = po.pofile()

        previouscontext = ''
        for inputunit in tsfile.units:
            contexts = inputunit.getcontext().split('\n')

            context = contexts[0]
            if context != previouscontext:
                previouscontext = context
                messagenum = 0

            disambiguation = ''
            if len(contexts) > 1:
                disambiguation = contexts[1]
            messagenum += 1
            thepo = self.convertmessage(context, messagenum, inputunit.source,
                                        inputunit.target, disambiguation,
                                        inputunit.getnotes(),
                                        inputunit._gettype())
            thetargetfile.addunit(thepo)

        thetargetfile.removeduplicates(self.duplicatestyle)
        return thetargetfile
예제 #4
0
 def test_target(self):
     tsfile = ts.tsfile()
     tsunit = tsfile.addsourceunit("Concept")
     tsunit.target = "Konsep"
     newfile = ts.tsfile.parsestring(tsfile.serialize())
     print(tsfile.serialize())
     assert newfile.findunit("Concept").target == "Konsep"
예제 #5
0
 def test_source(self):
     tsfile = ts.tsfile()
     tsunit = tsfile.addsourceunit("Concept")
     tsunit.source = "Term"
     newfile = ts.tsfile.parsestring(bytes(tsfile))
     print(bytes(tsfile))
     assert newfile.findunit("Concept") is None
     assert newfile.findunit("Term") is not None
예제 #6
0
 def test_source(self):
     tsfile = ts.tsfile()
     tsunit = tsfile.addsourceunit("Concept")
     tsunit.source = "Term"
     newfile = ts.tsfile.parsestring(tsfile.serialize())
     print(tsfile.serialize())
     assert newfile.findunit("Concept") is None
     assert newfile.findunit("Term") is not None
예제 #7
0
 def test_plurals(self):
     """Test basic plurals"""
     tsfile = ts.tsfile()
     tsunit = tsfile.addsourceunit("File(s)")
     tsunit.target = [u"Leêr", u"Leêrs"]
     newfile = ts.tsfile.parsestring(bytes(tsfile))
     print(bytes(tsfile))
     checkunit = newfile.findunit("File(s)")
     assert checkunit.target == [u"Leêr", u"Leêrs"]
     assert checkunit.hasplural()
예제 #8
0
 def test_plurals(self):
     """Test basic plurals"""
     tsfile = ts.tsfile()
     tsunit = tsfile.addsourceunit("File(s)")
     tsunit.target = [u"Leêr", u"Leêrs"]
     newfile = ts.tsfile.parsestring(tsfile.serialize())
     print(tsfile.serialize())
     checkunit = newfile.findunit("File(s)")
     assert checkunit.target == [u"Leêr", u"Leêrs"]
     assert checkunit.hasplural()
예제 #9
0
 def test_basic(self):
     tsfile = ts.tsfile()
     assert tsfile.units == []
     tsfile.addsourceunit("Bla")
     assert len(tsfile.units) == 1
     newfile = ts.tsfile.parsestring(bytes(tsfile))
     print(bytes(tsfile))
     assert len(newfile.units) == 1
     assert newfile.units[0].source == "Bla"
     assert newfile.findunit("Bla").source == "Bla"
     assert newfile.findunit("dit") is None
예제 #10
0
 def test_basic(self):
     tsfile = ts.tsfile()
     assert tsfile.units == []
     tsfile.addsourceunit("Bla")
     assert len(tsfile.units) == 1
     newfile = ts.tsfile.parsestring(tsfile.serialize())
     print(tsfile.serialize())
     assert len(newfile.units) == 1
     assert newfile.units[0].source == "Bla"
     assert newfile.findunit("Bla").source == "Bla"
     assert newfile.findunit("dit") is None