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)
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"
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
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"
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
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
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()
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()
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
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